forked from lix-project/lix
getSelfExe(): Support macOS
This commit is contained in:
parent
184f4e40de
commit
1e55ee2961
|
@ -29,6 +29,7 @@
|
|||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/syscall.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -635,10 +636,17 @@ Path getDataDir()
|
|||
|
||||
std::optional<Path> getSelfExe()
|
||||
{
|
||||
static std::optional<Path> cached = []()
|
||||
static auto cached = []() -> std::optional<Path>
|
||||
{
|
||||
#if __linux__
|
||||
return readLink("/proc/self/exe");
|
||||
#elif __APPLE__
|
||||
char buf[1024];
|
||||
uint32_t size = sizeof(buf);
|
||||
if (_NSGetExecutablePath(buf, &size) == 0)
|
||||
return buf;
|
||||
else
|
||||
return std::nullopt;
|
||||
#else
|
||||
return std::nullopt;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue