Code
bool GetExePath(string& _outPath)
{
char _linkPath[PATH_MAX],_pathBuf[PATH_MAX],_pid_s[10];
memset(_linkPath,'\0',sizeof(_linkPath));
int _pid = getpid();
strcpy(_linkPath,"/proc/");
if(0 > snprintf(_pid_s,10,"%d",_pid))
return false;
strcat(_linkPath,_pid_s);
strcat(_linkPath,"/exe");
if(0 > readlink(_linkPath,_pathBuf,PATH_MAX))
return false;
int i = strlen(_pathBuf);
for(; i > 0 ; --i)
if(_pathBuf[i] == '/')
break;
_outPath = string(_pathBuf,i);
return true;
}
posted @
2009-09-07 18:15
joe.zhou
阅读(
105)
评论()
编辑
收藏
举报