#include <limits.h> /* PATH_MAX */
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
int main(int argc, char **argv) {
char buf[PATH_MAX + 1]; /* not sure about the "+ 1" */
char *res = realpath(argv[0], buf);
if (res) {
printf("This source is at %s.dir:%s/n", buf,dirname(buf));
} else {
perror("realpath");
exit(EXIT_FAILURE);
}
return 0;
}
macos上获得程序文件所在的路径
最新推荐文章于 2023-10-06 01:19:04 发布