diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-18 14:51:23 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-06-18 14:51:23 -0400 |
| commit | c757984879687e465c6470fc1347cf0f14e46dcc (patch) | |
| tree | 9827a65bfcc0041a279d8a75b567cba83f9c5b16 /src/os.cpp | |
| parent | 84a700f97240eb2d4c65554d9be43bae9fa6d4ae (diff) | |
| parent | 1ca90b585692c9611c64412844d2f3a7b3e11340 (diff) | |
| download | zig-c757984879687e465c6470fc1347cf0f14e46dcc.tar.gz zig-c757984879687e465c6470fc1347cf0f14e46dcc.zip | |
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'src/os.cpp')
| -rw-r--r-- | src/os.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/os.cpp b/src/os.cpp index 97462bd658..b7d2fd1de0 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -989,12 +989,29 @@ int os_self_exe_path(Buf *out_path) { } #elif defined(ZIG_OS_DARWIN) + // How long is the executable's path? 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); + + Buf *tmp = buf_alloc_fixed(u32_len); + + // Fill the executable path. + int ret2 = _NSGetExecutablePath(buf_ptr(tmp), &u32_len); assert(ret2 == 0); + + // According to libuv project, PATH_MAX*2 works around a libc bug where + // the resolved path is sometimes bigger than PATH_MAX. + buf_resize(out_path, PATH_MAX*2); + char *real_path = realpath(buf_ptr(tmp), buf_ptr(out_path)); + if (!real_path) { + buf_init_from_buf(out_path, tmp); + return 0; + } + + // Resize out_path for the correct length. + buf_resize(out_path, strlen(buf_ptr(out_path))); + return 0; #elif defined(ZIG_OS_LINUX) buf_resize(out_path, 256); |
