-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path #1128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -989,12 +989,29 @@ int os_self_exe_path(Buf *out_path) { | |
| } | ||
|
|
||
| #elif defined(ZIG_OS_DARWIN) | ||
| // How long is the executable's path? | ||
| uint32_t u32_len = 0; | ||
| int ret1 = _NSGetExecutablePath(nullptr, &u32_len); | ||
| assert(ret1 != 0); | ||
| buf_resize(out_path, u32_len); | ||
| int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len); | ||
|
|
||
| // 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not relevant to Zig but in libuv we allocate 2*PATH_MAX to work around a bug in old versions of Apple's libc where the expanded path is sometimes > PATH_MAX.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I'll throw that in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| char *real_path = realpath(buf_ptr(tmp), buf_ptr(out_path)); | ||
| assert(real_path == buf_ptr(out_path)); | ||
|
|
||
| // Deallocate our scratch space. | ||
| buf_deinit(tmp); | ||
|
|
||
| // Resize out_path for the correct length. | ||
| buf_resize(out_path, strlen(buf_ptr(out_path))); | ||
|
|
||
| return 0; | ||
| #elif defined(ZIG_OS_LINUX) | ||
| buf_resize(out_path, 256); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might just be me but I personally don't really like comments that just say what the code on the line below does.
As a rule of thumb, comments should explain what won't be obvious from just looking at the code, not restate the code in prose.
edit: hadn't noticed this has been merged between starting and finishing the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The justification is that it makes code faster to read.