authorgravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-10-11 12:23:52+00:00
committergravatar for semarie@online.frSébastien Marie <semarie@online.fr> 2020-10-11 12:23:52+00:00
loga6dc2b7fcc2e1e73130eb0e762cac4ab884d20c2
tree6c2ab1a03cbb3e971d96c961b870931729c9a73a
parent4c4211ea8e7c553c78ed25f52b60000f1f066503

openbsd: selfExePath adjustements


1 files changed, 5 insertions(+), 6 deletions(-)

lib/std/fs.zig+5-6
...@@ -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];
22472247 } 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 PATH2248 // 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 "";
22582257
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 file2260 // 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)