Implement util::executable_path() for macos
This commit is contained in:
parent
bb0c3bb178
commit
810770564e
1 changed files with 10 additions and 0 deletions
|
|
@ -8,6 +8,10 @@
|
|||
#include <winerror.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
namespace psemek::util
|
||||
{
|
||||
|
||||
|
|
@ -29,6 +33,12 @@ namespace psemek::util
|
|||
return std::filesystem::path(result);
|
||||
#elif defined __linux__
|
||||
return std::filesystem::canonical("/proc/self/exe");
|
||||
#elif defined __APPLE__
|
||||
uint32_t path_length = 0;
|
||||
_NSGetExecutablePath(nullptr, &path_length);
|
||||
std::string path(path_length, '\0');
|
||||
_NSGetExecutablePath(path.data(), &path_length);
|
||||
return std::filesystem::path(std::move(path));
|
||||
#else
|
||||
throw exception("executable_path() is not implemented for this platform");
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue