| ... | @@ -7194,15 +7194,14 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex | ... | @@ -7194,15 +7194,14 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex |
| 7194 | if (std.mem.indexOf(u8, argv0, "/") != null) { | 7194 | if (std.mem.indexOf(u8, argv0, "/") != null) { |
| 7195 | // argv[0] is a path (relative or absolute): use realpath(3) directly | 7195 | // argv[0] is a path (relative or absolute): use realpath(3) directly |
| 7196 | var real_path_buf: [posix.PATH_MAX]u8 = undefined; | 7196 | var real_path_buf: [posix.PATH_MAX]u8 = undefined; |
| 7197 | const real_path = Io.Dir.realPathFileAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) { | 7197 | const real_path_len = Io.Dir.realPathFileAbsolute(ioBasic(t), argv0, &real_path_buf) catch |err| switch (err) { |
| 7198 | error.NetworkNotFound => unreachable, // Windows-only | 7198 | error.NetworkNotFound => unreachable, // Windows-only |
| 7199 | else => |e| return e, | 7199 | else => |e| return e, |
| 7200 | }; | 7200 | }; |
| 7201 | if (real_path.len > out_buffer.len) | 7201 | if (real_path_len > out_buffer.len) |
| 7202 | return error.NameTooLong; | 7202 | return error.NameTooLong; |
| 7203 | const result = out_buffer[0..real_path.len]; | 7203 | @memcpy(out_buffer[0..real_path_len], real_path_buf[0..real_path_len]); |
| 7204 | @memcpy(result, real_path); | 7204 | return real_path_len; |
| 7205 | return result.len; | | |
| 7206 | } else if (argv0.len != 0) { | 7205 | } else if (argv0.len != 0) { |
| 7207 | // argv[0] is not empty (and not a path): search it inside PATH | 7206 | // argv[0] is not empty (and not a path): search it inside PATH |
| 7208 | const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound; | 7207 | const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound; |
| ... | @@ -7214,13 +7213,12 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex | ... | @@ -7214,13 +7213,12 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex |
| 7214 | }, 0) catch continue; | 7213 | }, 0) catch continue; |
| 7215 | | 7214 | |
| 7216 | var real_path_buf: [posix.PATH_MAX]u8 = undefined; | 7215 | var real_path_buf: [posix.PATH_MAX]u8 = undefined; |
| 7217 | if (Io.Dir.realPathFileAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| { | 7216 | if (Io.Dir.realPathFileAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path_len| { |
| 7218 | // found a file, and hope it is the right file | 7217 | // found a file, and hope it is the right file |
| 7219 | if (real_path.len > out_buffer.len) | 7218 | if (real_path_len > out_buffer.len) |
| 7220 | return error.NameTooLong; | 7219 | return error.NameTooLong; |
| 7221 | const result = out_buffer[0..real_path.len]; | 7220 | @memcpy(out_buffer[0..real_path_len], real_path_buf[0..real_path_len]); |
| 7222 | @memcpy(result, real_path); | 7221 | return real_path_len; |
| 7223 | return result.len; | | |
| 7224 | } else |_| continue; | 7222 | } else |_| continue; |
| 7225 | } | 7223 | } |
| 7226 | } | 7224 | } |