| ... | @@ -2244,19 +2244,18 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { | ... | @@ -2244,19 +2244,18 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { |
| 2244 | return error.NameTooLong; | 2244 | return error.NameTooLong; |
| 2245 | mem.copy(u8, out_buffer, real_path); | 2245 | mem.copy(u8, out_buffer, real_path); |
| 2246 | return out_buffer[0..real_path.len]; | 2246 | return out_buffer[0..real_path.len]; |
| 2247 | | 2247 | } else if (argv0.len != 0) { |
| 2248 | } else if (os.argv[0][0] != '\x00') { | | |
| 2249 | // argv[0] is not empty (and not a path): search it inside PATH | 2248 | // argv[0] is not empty (and not a path): search it inside PATH |
| 2250 | const paths = std.os.getenv("PATH") orelse ""; | 2249 | const PATH = std.os.getenv("PATH") orelse ""; |
| 2251 | var path_it = mem.split(paths, ":"); | 2250 | var path_it = mem.tokenize(PATH, &[_]u8{path.delimiter}); |
| 2252 | while (path_it.next()) |a_path| { | 2251 | while (path_it.next()) |a_path| { |
| 2253 | var resolved_path_buf: [MAX_PATH_BYTES:0]u8 = undefined; | 2252 | var resolved_path_buf: [MAX_PATH_BYTES-1:0]u8 = undefined; |
| 2254 | const resolved_path = std.fmt.bufPrint(&resolved_path_buf, "{}/{}\x00", .{ | 2253 | const resolved_path = std.fmt.bufPrint(&resolved_path_buf, "{}/{}\x00", .{ |
| 2255 | a_path, | 2254 | a_path, |
| 2256 | os.argv[0], | 2255 | os.argv[0], |
| 2257 | }) catch ""; | 2256 | }) catch ""; |
| 2258 | | 2257 | |
| 2259 | var real_path_buf: [MAX_PATH_BYTES:0]u8 = undefined; | 2258 | var real_path_buf: [MAX_PATH_BYTES]u8 = undefined; |
| 2260 | if (os.realpathZ(&resolved_path_buf, &real_path_buf) catch null) |real_path| { | 2259 | if (os.realpathZ(&resolved_path_buf, &real_path_buf) catch null) |real_path| { |
| 2261 | // found a file, and hope it is the right file | 2260 | // found a file, and hope it is the right file |
| 2262 | if (real_path.len > out_buffer.len) | 2261 | if (real_path.len > out_buffer.len) |