我有了许多不同的操作系统(多操作系统)获取可执行文件路径
二进制程序我需要得到二进制(认为自动更新)的位置
怎么做的'你的'操作系统?
(把它看成是的,各种各样:)一个挑战)
编辑注:程序可以是便携式(流掉闪存驱动器等)或安装(如最初在.deb文件格式)
EDIT2:这里是我已经:
/**
* Get the location of the executable
* @return the location of the executable, as a string.
*/
const char *GetExecutableLocation()
{
const char *path;
char buf[1024];
#if defined (WIN32) || defined (WIN64)
GetModuleFileName(path, &size);
#elif defined (__APPLE__)
_NSGetExecutablePath(path, &size);
#elif defined(UNIX)
if (readlink("/proc/self/exe", buf, sizeof(buf)) == -1) path = buf;
#elif defined(__FreeBSD__)
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
sysctl(mib, 4, buf, sizeof(buf), NULL, 0);
path = buf;
#elif defined(SUNOS)
path = getexecname();
#endif
return path;
}
(请注意,我只测试了Unix的部分,我不知道别的)
可能是'argv [0]''可能? –