authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 12:16:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 12:16:47-04:00
logc09c3902c441bbf5dd1421f6ccd9f0dac5c6d96e
tree4d728057e26cc2f9fcdd4edf39adf41f57054e56
parent48985a7e684ff32eb5d419a89eac3b92c08c3ee9
parentc7057bd25b2a99e5ac61963efd588f5fe4ba93c6

Merge branch 'fix-1117-macos-realpath' of https://github.com/binary132/zig into binary132-fix-1117-macos-realpath


1 files changed, 19 insertions(+), 2 deletions(-)

src/os.cpp+19-2
......@@ -989,12 +989,29 @@ int os_self_exe_path(Buf *out_path) {
989989 }
990990
991991#elif defined(ZIG_OS_DARWIN)
992 // How long is the executable's path?
992993 uint32_t u32_len = 0;
993994 int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
994995 assert(ret1 != 0);
995 buf_resize(out_path, u32_len);
996 int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len);
996
997 // Make a buffer having room for the temp path.
998 Buf *tmp = buf_alloc_fixed(u32_len);
999
1000 // Fill the executable path.
1001 int ret2 = _NSGetExecutablePath(buf_ptr(tmp), &u32_len);
9971002 assert(ret2 == 0);
1003
1004 // Resolve the real path from that.
1005 buf_resize(out_path, PATH_MAX);
1006 char *real_path = realpath(buf_ptr(tmp), buf_ptr(out_path));
1007 assert(real_path == buf_ptr(out_path));
1008
1009 // Deallocate our scratch space.
1010 buf_deinit(tmp);
1011
1012 // Resize out_path for the correct length.
1013 buf_resize(out_path, strlen(buf_ptr(out_path)));
1014
9981015 return 0;
9991016#elif defined(ZIG_OS_LINUX)
10001017 buf_resize(out_path, 256);