Skip to content

Commit e3d3964

Browse files
committed
netbsd: getFdPath: F_GETPATH implementation
1 parent 05ddff0 commit e3d3964

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/std/c/netbsd.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,17 @@ pub const F = struct {
690690
pub const SETFD = 2;
691691
pub const GETFL = 3;
692692
pub const SETFL = 4;
693-
694693
pub const GETOWN = 5;
695694
pub const SETOWN = 6;
696-
697695
pub const GETLK = 7;
698696
pub const SETLK = 8;
699697
pub const SETLKW = 9;
698+
pub const CLOSEM = 10;
699+
pub const MAXFD = 11;
700+
pub const DUPFD_CLOEXEC = 12;
701+
pub const GETNOSIGPIPE = 13;
702+
pub const SETNOSIGPIPE = 14;
703+
pub const GETPATH = 15;
700704

701705
pub const RDLCK = 1;
702706
pub const WRLCK = 3;

lib/std/os.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5195,6 +5195,23 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
51955195
const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
51965196
return out_buffer[0..len];
51975197
},
5198+
.netbsd => {
5199+
if (comptime builtin.os.version_range.semver.max.order(.{ .major = 10, .minor = 0 }) == .lt) {
5200+
@compileError("querying for canonical path of a handle is unsupported on this host");
5201+
}
5202+
@memset(out_buffer, 0, MAX_PATH_BYTES);
5203+
switch (errno(system.fcntl(fd, F.GETPATH, out_buffer))) {
5204+
.SUCCESS => {},
5205+
.ACCES => return error.AccessDenied,
5206+
.BADF => return error.FileNotFound,
5207+
.NOENT => return error.FileNotFound,
5208+
.NOMEM => return error.SystemResources,
5209+
.RANGE => return error.NameTooLong,
5210+
else => |err| return unexpectedErrno(err),
5211+
}
5212+
const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
5213+
return out_buffer[0..len];
5214+
},
51985215
else => @compileError("querying for canonical path of a handle is unsupported on this host"),
51995216
}
52005217
}

0 commit comments

Comments
 (0)