From 82747dae2191907440d40ebe13406d0d7f8045a0 Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Wed, 31 Jan 2018 12:16:27 +0100 Subject: [PATCH] Implement getExecutableFolder for Mac OS The /proc/self/exe link does not exist on Mac OS X. See https://stackoverflow.com/questions/22675457/what-is-the-equivalent-of-proc-self-exe-on-macintosh-os-x-mavericks --- AirLib/src/common/common_utils/FileSystem.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/AirLib/src/common/common_utils/FileSystem.cpp b/AirLib/src/common/common_utils/FileSystem.cpp index ac28a036ca..5ead7efd0b 100644 --- a/AirLib/src/common/common_utils/FileSystem.cpp +++ b/AirLib/src/common/common_utils/FileSystem.cpp @@ -32,6 +32,10 @@ #include #endif +#ifdef __APPLE__ +#include +#endif + using namespace common_utils; // File names are unicode (std::wstring), because users can create folders containing unicode characters on both @@ -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));