diff --git a/src/base/fs_unix.h b/src/base/fs_unix.h index f8456a590..4ce5bdcfc 100644 --- a/src/base/fs_unix.h +++ b/src/base/fs_unix.h @@ -9,6 +9,15 @@ #include #include #include +#include + +#if __APPLE__ +#include +#endif + +#include "base/path.h" + +#define MAXPATHLEN 1024 namespace base { @@ -44,7 +53,22 @@ void remove_directory(const string& path) string get_app_path() { - return getexecname(); + std::vector path(MAXPATHLEN); + +#if __APPLE__ + + uint32_t size = path.size(); + while (_NSGetExecutablePath(&path[0], &size) == -1) + path.resize(size); + +#else + + if (readlink("/proc/self/exe", &path[0], path.size()) > 0) + return std::string(&path[0]); + +#endif + + return std::string(); } string get_temp_path()