Commit c3724ec506

Andrew Kelley <superjoe30@gmail.com>
2018-03-31 08:12:44
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 parent 5d5feb1
Changed files (1)
src
src/os.cpp
@@ -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 (;;) {