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>
|
#include <winerror.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace psemek::util
|
namespace psemek::util
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -29,6 +33,12 @@ namespace psemek::util
|
||||||
return std::filesystem::path(result);
|
return std::filesystem::path(result);
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
return std::filesystem::canonical("/proc/self/exe");
|
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
|
#else
|
||||||
throw exception("executable_path() is not implemented for this platform");
|
throw exception("executable_path() is not implemented for this platform");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue