authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 12:19:16-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 12:19:16-04:00
log1aa93808b18e8c54b3227b0039f2821b0e910b27
treeec1061cfe181ad97d84ddbc139354e8d086fcda9
parent48985a7e684ff32eb5d419a89eac3b92c08c3ee9
parent4ce36a64755b4b2ca8bb28e3ac91b23dfe90ade8

Merge branch '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 if (!real_path) {
1008 buf_init_from_buf(out_path, tmp);
1009 return 0;
1010 }
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);