Skip to content

Commit

Permalink
Merge pull request #29 from OpenDDS/support-macos
Browse files Browse the repository at this point in the history
Get executable path in macOS
  • Loading branch information
jrw972 authored Aug 28, 2024
2 parents 904c47f + 534291a commit 5678598
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/platformIndependent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include <filesystem>
#include <string>

#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif

namespace pi
{
/// Returns the full path to the executable currently running.
Expand Down Expand Up @@ -41,7 +45,19 @@ namespace pi
strExecutablePath.resize(nSizeReturned);
#endif

#else //NOT defined( WIN32 ) || defined( WIN64 )
#elif defined(__APPLE__)
uint32_t nBufferExePathSize = nPathIncrementSize;
strExecutablePath.resize(nBufferExePathSize, '\0');
int ret = _NSGetExecutablePath(&strExecutablePath[0], &nBufferExePathSize);
if (ret != 0) {
strExecutablePath.resize(nBufferExePathSize, '\0');
ret = _NSGetExecutablePath(&strExecutablePath[0], &nBufferExePathSize);
if (ret != 0) {
throw std::runtime_error("Error getting the executable path");
}
}

#else // !defined( WIN32 ) && !defined( WIN64 ) && !defined(__APPLE__)
size_t nBufferExePathSize = 0;
ssize_t nSizeReturned = 0;
// readlink returns the size copied to the supplied buffer, if it fills the
Expand Down

0 comments on commit 5678598

Please sign in to comment.