| author | |
| committer | |
| log | 4396373ccb7182defa6cd084646b009de82f0b18 |
| tree | 3b91fa13bd7c32d3925a2b59de0799659871519d |
| parent | e31cc80130ee7e4b61b63d1d1a0fc0a84fbb15ff |
| parent | 276598346a1f04bcfbe4982ea3c766aa79cad681 |
| signature |
fix symlink path not being resolved in darwin3 files changed, 14 insertions(+), 6 deletions(-)
lib/std/c/darwin.zig+1-1| ... | @@ -12,7 +12,7 @@ usingnamespace @import("../os/bits.zig"); | ... | @@ -12,7 +12,7 @@ usingnamespace @import("../os/bits.zig"); |
| 12 | 12 | ||
| 13 | extern "c" fn __error() *c_int; | 13 | extern "c" fn __error() *c_int; |
| 14 | pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32; | 14 | pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32; |
| 15 | pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int; | 15 | pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int; |
| 16 | pub extern "c" fn _dyld_image_count() u32; | 16 | pub extern "c" fn _dyld_image_count() u32; |
| 17 | pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header; | 17 | pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header; |
| 18 | pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize; | 18 | pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize; |
lib/std/fs.zig+12-4| ... | @@ -2162,7 +2162,7 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File { | ... | @@ -2162,7 +2162,7 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File { |
| 2162 | return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags); | 2162 | return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags); |
| 2163 | } | 2163 | } |
| 2164 | 2164 | ||
| 2165 | pub const SelfExePathError = os.ReadLinkError || os.SysCtlError; | 2165 | pub const SelfExePathError = os.ReadLinkError || os.SysCtlError || os.RealPathError; |
| 2166 | 2166 | ||
| 2167 | /// `selfExePath` except allocates the result on the heap. | 2167 | /// `selfExePath` except allocates the result on the heap. |
| 2168 | /// Caller owns returned memory. | 2168 | /// Caller owns returned memory. |
| ... | @@ -2190,10 +2190,18 @@ pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 { | ... | @@ -2190,10 +2190,18 @@ pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 { |
| 2190 | /// TODO make the return type of this a null terminated pointer | 2190 | /// TODO make the return type of this a null terminated pointer |
| 2191 | pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { | 2191 | pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 2192 | if (is_darwin) { | 2192 | if (is_darwin) { |
| 2193 | var u32_len: u32 = @intCast(u32, math.min(out_buffer.len, math.maxInt(u32))); | 2193 | // Note that _NSGetExecutablePath() will return "a path" to |
| 2194 | const rc = std.c._NSGetExecutablePath(out_buffer.ptr, &u32_len); | 2194 | // the executable not a "real path" to the executable. |
| 2195 | var symlink_path_buf: [MAX_PATH_BYTES:0]u8 = undefined; | ||
| 2196 | var u32_len: u32 = MAX_PATH_BYTES + 1; // include the sentinel | ||
| 2197 | const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len); | ||
| 2195 | if (rc != 0) return error.NameTooLong; | 2198 | if (rc != 0) return error.NameTooLong; |
| 2196 | return mem.spanZ(@ptrCast([*:0]u8, out_buffer)); | 2199 | |
| 2200 | var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; | ||
| 2201 | const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf); | ||
| 2202 | if (real_path.len > out_buffer.len) return error.NameTooLong; | ||
| 2203 | std.mem.copy(u8, out_buffer, real_path); | ||
| 2204 | return out_buffer[0..real_path.len]; | ||
| 2197 | } | 2205 | } |
| 2198 | switch (builtin.os.tag) { | 2206 | switch (builtin.os.tag) { |
| 2199 | .linux => return os.readlinkZ("/proc/self/exe", out_buffer), | 2207 | .linux => return os.readlinkZ("/proc/self/exe", out_buffer), |
lib/std/os.zig+1-1| ... | @@ -3993,7 +3993,7 @@ pub const RealPathError = error{ | ... | @@ -3993,7 +3993,7 @@ pub const RealPathError = error{ |
| 3993 | /// Expands all symbolic links and resolves references to `.`, `..`, and | 3993 | /// Expands all symbolic links and resolves references to `.`, `..`, and |
| 3994 | /// extra `/` characters in `pathname`. | 3994 | /// extra `/` characters in `pathname`. |
| 3995 | /// The return value is a slice of `out_buffer`, but not necessarily from the beginning. | 3995 | /// The return value is a slice of `out_buffer`, but not necessarily from the beginning. |
| 3996 | /// See also `realpathC` and `realpathW`. | 3996 | /// See also `realpathZ` and `realpathW`. |
| 3997 | pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { | 3997 | pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { |
| 3998 | if (builtin.os.tag == .windows) { | 3998 | if (builtin.os.tag == .windows) { |
| 3999 | const pathname_w = try windows.sliceToPrefixedFileW(pathname); | 3999 | const pathname_w = try windows.sliceToPrefixedFileW(pathname); |