Skip to content

Commit

Permalink
Implement getExecutableFolder for Mac OS
Browse files Browse the repository at this point in the history
  • Loading branch information
aburgm committed Jan 31, 2018
1 parent 6d927cd commit 82747da
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions AirLib/src/common/common_utils/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <errno.h>
#endif

#ifdef __APPLE__
#include <mach-o/dyld.h>
#endif

using namespace common_utils;

// File names are unicode (std::wstring), because users can create folders containing unicode characters on both
Expand Down Expand Up @@ -105,6 +109,15 @@ std::string FileSystem::getExecutableFolder() {
HRESULT hr = GetLastError();
throw std::invalid_argument(Utils::stringf("Error getting executable folder - hModule is null. Last error = %d", hr));
}
#elif __APPLE__
char szPath[8192];
uint32_t size = sizeof(szPath);

if (_NSGetExecutablePath(szPath, &size) != 0) {
throw std::invalid_argument("Error getting executable folder, path is too long");
}

path = std::string(szPath);
#else
char szPath[8192];
readlink("/proc/self/exe", szPath, sizeof(szPath));
Expand Down

0 comments on commit 82747da

Please sign in to comment.