diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-06-23 01:32:17 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-06-23 01:32:46 +0200 |
commit | 1e55ee2961eabd6016dfef1793996ded97c9054c (patch) | |
tree | a08d8b9e65a7149b7267f0b6aa72c3c0368eb03e /src/libutil | |
parent | 184f4e40de0960deccad2147099ea232e5e036c3 (diff) |
getSelfExe(): Support macOS
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 82628461c..28df30fef 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -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 |