authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-31 02:12:44-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-31 02:12:44-04:00
logc3724ec506a9e3a4b23a145a733050c17321da9d
tree9eeef4d13b4888507cfb502791266bacbde7d304
parent5d5feb11deb797bbecb8f3676457a74056f09496

implement os_self_exe_path in the c++ compiler for darwin

ported from the zig std lib this fixes looking for zig std lib at runtime on darwin

1 files changed, 8 insertions(+), 1 deletions(-)

src/os.cpp+8-1
...@@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t;...@@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t;
45#if defined(__MACH__)45#if defined(__MACH__)
46#include <mach/clock.h>46#include <mach/clock.h>
47#include <mach/mach.h>47#include <mach/mach.h>
48#include <mach-o/dyld.h>
48#endif49#endif
4950
50#if defined(ZIG_OS_WINDOWS)51#if defined(ZIG_OS_WINDOWS)
...@@ -923,7 +924,13 @@ int os_self_exe_path(Buf *out_path) {...@@ -923,7 +924,13 @@ int os_self_exe_path(Buf *out_path) {
923 }924 }
924925
925#elif defined(ZIG_OS_DARWIN)926#elif defined(ZIG_OS_DARWIN)
926 return ErrorFileNotFound;927 uint32_t u32_len = 0;
928 int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
929 assert(ret1 != 0);
930 buf_resize(out_path, u32_len);
931 int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len);
932 assert(ret2 == 0);
933 return 0;
927#elif defined(ZIG_OS_LINUX)934#elif defined(ZIG_OS_LINUX)
928 buf_resize(out_path, 256);935 buf_resize(out_path, 256);
929 for (;;) {936 for (;;) {