authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-10-02 19:33:14+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-10-02 19:33:14+02:00
logf841ea77e2cb7ad2ee4ecf993206f0c29d087131
treec18cbb48354f9d3c06b294ff9b9948eb21a8761c
parenta2074c1ec31ab553aea4232dfdc760a0442aeddf

make symlink buffer null-terminated

Signed-off-by: Loris Cro <kappaloris@gmail.com>

2 files changed, 3 insertions(+), 3 deletions(-)

lib/std/c/darwin.zig+1-1
......@@ -12,7 +12,7 @@ usingnamespace @import("../os/bits.zig");
1212
1313extern "c" fn __error() *c_int;
1414pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
15pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
15pub extern "c" fn _NSGetExecutablePath(buf: [*:0]u8, bufsize: *u32) c_int;
1616pub extern "c" fn _dyld_image_count() u32;
1717pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
1818pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
lib/std/fs.zig+2-2
......@@ -2192,13 +2192,13 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
21922192 if (is_darwin) {
21932193 // Note that _NSGetExecutablePath() will return "a path" to
21942194 // the executable not a "real path" to the executable.
2195 var symlink_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2195 var symlink_path_buf: [MAX_PATH_BYTES:0]u8 = undefined;
21962196 var u32_len: u32 = MAX_PATH_BYTES;
21972197 const rc = std.c._NSGetExecutablePath(&symlink_path_buf, &u32_len);
21982198 if (rc != 0) return error.NameTooLong;
21992199
22002200 var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2201 const real_path = try std.os.realpathZ(@ptrCast([*:0]u8, &symlink_path_buf), &real_path_buf);
2201 const real_path = try std.os.realpathZ(&symlink_path_buf, &real_path_buf);
22022202 if (real_path.len > out_buffer.len) return error.NameTooLong;
22032203 std.mem.copy(u8, out_buffer, real_path);
22042204 return out_buffer[0..real_path.len];