mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 00:06:16 +02:00
getSelfExe(): Support macOS
This commit is contained in:
parent
184f4e40de
commit
1e55ee2961
1 changed files with 9 additions and 1 deletions
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -635,10 +636,17 @@ Path getDataDir()
|
||||||
|
|
||||||
std::optional<Path> getSelfExe()
|
std::optional<Path> getSelfExe()
|
||||||
{
|
{
|
||||||
static std::optional<Path> cached = []()
|
static auto cached = []() -> std::optional<Path>
|
||||||
{
|
{
|
||||||
#if __linux__
|
#if __linux__
|
||||||
return readLink("/proc/self/exe");
|
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
|
#else
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue