stage1: update darwin code to workaround old libc bug

See #1128
This commit is contained in:
Andrew Kelley 2018-06-18 12:54:03 -04:00
parent 1aa93808b1
commit cd4676a233

View File

@ -994,15 +994,15 @@ int os_self_exe_path(Buf *out_path) {
int ret1 = _NSGetExecutablePath(nullptr, &u32_len);
assert(ret1 != 0);
// Make a buffer having room for the temp path.
Buf *tmp = buf_alloc_fixed(u32_len);
// Fill the executable path.
int ret2 = _NSGetExecutablePath(buf_ptr(tmp), &u32_len);
assert(ret2 == 0);
// Resolve the real path from that.
buf_resize(out_path, PATH_MAX);
// 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);