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
This commit is contained in:
Andrew Kelley 2018-03-31 02:12:44 -04:00
parent 5d5feb11de
commit c3724ec506

View File

@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t;
#if defined(__MACH__)
#include <mach/clock.h>
#include <mach/mach.h>
#include <mach-o/dyld.h>
#endif
#if defined(ZIG_OS_WINDOWS)
@ -923,7 +924,13 @@ int os_self_exe_path(Buf *out_path) {
}
#elif defined(ZIG_OS_DARWIN)
return ErrorFileNotFound;
uint32_t u32_len = 0;
int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
assert(ret1 != 0);
buf_resize(out_path, u32_len);
int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len);
assert(ret2 == 0);
return 0;
#elif defined(ZIG_OS_LINUX)
buf_resize(out_path, 256);
for (;;) {