diff --git a/src/futils.cpp b/src/futils.cpp index 3e30c9996..c746838d5 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -38,6 +38,10 @@ namespace fs = std::experimental::filesystem; #include // for stat() #endif +#if __has_include() +#include // for _NSGetExecutablePath() +#endif + #if defined(__FreeBSD__) // clang-format off #include @@ -360,9 +364,12 @@ std::string getProcessPath() { TCHAR pathbuf[MAX_PATH]; GetModuleFileName(nullptr, pathbuf, MAX_PATH); auto path = fs::path(pathbuf); -#elif __has_include() - char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; - proc_pidpath(getpid(), pathbuf, sizeof(pathbuf)); +#elif defined(__APPLE__) + char pathbuf[2048]; + uint32_t size = sizeof(pathbuf); + const int get_exec_path_failure = _NSGetExecutablePath(pathbuf, &size); + if (get_exec_path_failure) + return "unknown"; // pathbuf not big enough auto path = fs::path(pathbuf); #elif defined(__sun__) auto path = fs::read_symlink(Internal::stringFormat("/proc/%d/path/a.out", getpid()));