authorgravatar for bodie@synapsegarden.netBodie Solomon <bodie@synapsegarden.net> 2018-06-18 07:37:26-04:00
committergravatar for bodie@synapsegarden.netBodie Solomon <bodie@synapsegarden.net> 2018-06-18 07:40:31-04:00
logc7057bd25b2a99e5ac61963efd588f5fe4ba93c6
tree53cf3f180288da5d8968e6e26f4e355128b119c3
parent045682289243c6186363e984babc706c3ed93152
signaturelock-open Commit is signed but in an unrecognized format.

Fix 1117: Revise realpath scratch logic


1 files changed, 11 insertions(+), 10 deletions(-)

src/os.cpp+11-10
......@@ -994,23 +994,24 @@ int os_self_exe_path(Buf *out_path) {
994994 int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
995995 assert(ret1 != 0);
996996
997 // Make room for the executable path and resolved path in out_path,
998 // then subslice it for convenience.
999 buf_resize(out_path, u32_len + PATH_MAX);
1000 Buf *tmp = buf_slice(out_path, 0, u32_len);
1001 Buf *resolved = buf_slice(out_path, u32_len, u32_len + PATH_MAX);
997 // Make a buffer having room for the temp path.
998 Buf *tmp = buf_alloc_fixed(u32_len);
1002999
10031000 // Fill the executable path.
10041001 int ret2 = _NSGetExecutablePath(buf_ptr(tmp), &u32_len);
10051002 assert(ret2 == 0);
10061003
10071004 // Resolve the real path from that.
1008 char *real_path = realpath(buf_ptr(tmp), buf_ptr(resolved));
1009 assert(real_path == buf_ptr(resolved));
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)));
10101014
1011 // Write the real path back into the beginning of out_path, resize.
1012 buf_init_from_buf(out_path, resolved);
1013 assert(buf_len(out_path) == buf_len(resolved));
10141015 return 0;
10151016#elif defined(ZIG_OS_LINUX)
10161017 buf_resize(out_path, 256);