Get Running EXE Path && Change Working Path Under Linux
得到目前正在執行的程式路徑,並切換 working directory 至此路徑。
char buf[256] = {'\0'};
char *pch;
readlink("/proc/self/exe", buf, sizeof(buf));
if (pch = strrchr(buf, '/'))
{
*pch = '\0';
printf("working directory:%s\n", buf);
chdir(buf);
}