Implement util::executable_path() for macos

This commit is contained in:
Nikita Lisitsa 2026-06-30 23:46:26 +03:00
parent bb0c3bb178
commit 810770564e

View file

@ -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