authorgravatar for bodie@synapsegarden.netBodie Solomon <bodie@synapsegarden.net> 2018-06-18 07:01:59-04:00
committergravatar for bodie@synapsegarden.netBodie Solomon <bodie@synapsegarden.net> 2018-06-18 07:40:31-04:00
log045682289243c6186363e984babc706c3ed93152
treed4381ab303aba13ff07e6fb2fa09bd5e683c81d8
parente6b69151c0d30d2df95d1f92b65784eac7d186d9
signature Commit is signed but in an unrecognized format.

Fix 1117: Tweak realpath logic to use out_path as scratch space


1 files changed, 14 insertions(+), 14 deletions(-)

src/os.cpp+14-14
...@@ -994,23 +994,23 @@ int os_self_exe_path(Buf *out_path) {...@@ -994,23 +994,23 @@ int os_self_exe_path(Buf *out_path) {
994 int ret1 = _NSGetExecutablePath(nullptr, &u32_len);994 int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
995 assert(ret1 != 0);995 assert(ret1 != 0);
996996
997 // Allocate a buffer for this path.997 // Make room for the executable path and resolved path in out_path,
998 Buf *path_tmp = buf_alloc_fixed(u32_len);998 // then subslice it for convenience.
999 // Fill the buffer with the path, which may be a symlink.999 buf_resize(out_path, u32_len + PATH_MAX);
1000 int ret2 = _NSGetExecutablePath(buf_ptr(path_tmp), &u32_len);1000 Buf *tmp = buf_slice(out_path, 0, u32_len);
1001 Buf *resolved = buf_slice(out_path, u32_len, u32_len + PATH_MAX);
1002
1003 // Fill the executable path.
1004 int ret2 = _NSGetExecutablePath(buf_ptr(tmp), &u32_len);
1001 assert(ret2 == 0);1005 assert(ret2 == 0);
10021006
1003 // Make a buffer with room for the real path.1007 // Resolve the real path from that.
1004 Buf *resolve_tmp = buf_alloc_fixed(PATH_MAX);1008 char *real_path = realpath(buf_ptr(tmp), buf_ptr(resolved));
1009 assert(real_path == buf_ptr(resolved));
10051010
1006 // Fill it with the real resolved path.1011 // Write the real path back into the beginning of out_path, resize.
1007 char *real_path = realpath(buf_ptr(path_tmp), buf_ptr(resolve_tmp));1012 buf_init_from_buf(out_path, resolved);
1008 // IEEE Std 1003.1-2017: realpath() shall return a pointer to the1013 assert(buf_len(out_path) == buf_len(resolved));
1009 // buffer containing the resolved name.
1010 assert(real_path == buf_ptr(resolve_tmp));
1011
1012 // Resize out_path and copy the resulting resolved absolute path.
1013 buf_init_from_buf(out_path, resolve_tmp);
1014 return 0;1014 return 0;
1015#elif defined(ZIG_OS_LINUX)1015#elif defined(ZIG_OS_LINUX)
1016 buf_resize(out_path, 256);1016 buf_resize(out_path, 256);