mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 02:44:43 +01:00
openbsd: use Io.Dir.realPathFileAbsolute
This commit is contained in:
parent
486ed907f7
commit
90bc371f56
1 changed files with 8 additions and 10 deletions
|
|
@ -7194,15 +7194,14 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
|
|||
if (std.mem.indexOf(u8, argv0, "/") != null) {
|
||||
// argv[0] is a path (relative or absolute): use realpath(3) directly
|
||||
var real_path_buf: [posix.PATH_MAX]u8 = undefined;
|
||||
const real_path = Io.Dir.realPathFileAbsolute(ioBasic(t), std.os.argv[0], &real_path_buf) catch |err| switch (err) {
|
||||
const real_path_len = Io.Dir.realPathFileAbsolute(ioBasic(t), argv0, &real_path_buf) catch |err| switch (err) {
|
||||
error.NetworkNotFound => unreachable, // Windows-only
|
||||
else => |e| return e,
|
||||
};
|
||||
if (real_path.len > out_buffer.len)
|
||||
if (real_path_len > out_buffer.len)
|
||||
return error.NameTooLong;
|
||||
const result = out_buffer[0..real_path.len];
|
||||
@memcpy(result, real_path);
|
||||
return result.len;
|
||||
@memcpy(out_buffer[0..real_path_len], real_path_buf[0..real_path_len]);
|
||||
return real_path_len;
|
||||
} else if (argv0.len != 0) {
|
||||
// argv[0] is not empty (and not a path): search it inside PATH
|
||||
const PATH = posix.getenvZ("PATH") orelse return error.FileNotFound;
|
||||
|
|
@ -7214,13 +7213,12 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) std.process.Ex
|
|||
}, 0) catch continue;
|
||||
|
||||
var real_path_buf: [posix.PATH_MAX]u8 = undefined;
|
||||
if (Io.Dir.realPathFileAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path| {
|
||||
if (Io.Dir.realPathFileAbsolute(ioBasic(t), resolved_path, &real_path_buf)) |real_path_len| {
|
||||
// found a file, and hope it is the right file
|
||||
if (real_path.len > out_buffer.len)
|
||||
if (real_path_len > out_buffer.len)
|
||||
return error.NameTooLong;
|
||||
const result = out_buffer[0..real_path.len];
|
||||
@memcpy(result, real_path);
|
||||
return result.len;
|
||||
@memcpy(out_buffer[0..real_path_len], real_path_buf[0..real_path_len]);
|
||||
return real_path_len;
|
||||
} else |_| continue;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue