| ... | @@ -989,12 +989,29 @@ int os_self_exe_path(Buf *out_path) { | ... | @@ -989,12 +989,29 @@ int os_self_exe_path(Buf *out_path) { |
| 989 | } | 989 | } |
| 990 | | 990 | |
| 991 | #elif defined(ZIG_OS_DARWIN) | 991 | #elif defined(ZIG_OS_DARWIN) |
| | 992 | // How long is the executable's path? |
| 992 | uint32_t u32_len = 0; | 993 | uint32_t u32_len = 0; |
| 993 | int ret1 = _NSGetExecutablePath(nullptr, &u32_len); | 994 | int ret1 = _NSGetExecutablePath(nullptr, &u32_len); |
| 994 | assert(ret1 != 0); | 995 | assert(ret1 != 0); |
| 995 | buf_resize(out_path, u32_len); | 996 | |
| 996 | int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len); | 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); |
| 997 | assert(ret2 == 0); | 1002 | 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 | |
| 998 | return 0; | 1015 | return 0; |
| 999 | #elif defined(ZIG_OS_LINUX) | 1016 | #elif defined(ZIG_OS_LINUX) |
| 1000 | buf_resize(out_path, 256); | 1017 | buf_resize(out_path, 256); |