commit 7da9348637f82ca75e1100a2fce2d368f96b589f (tree)
parent 7f012eef0b7bd4dbccf796c2889495150f996fba
Author: Michael Dusan <michael.dusan@gmail.com>
Date: Mon, 2 Jan 2023 19:18:33 -0500
dragonfly: getFdPath: F_GETPATH implementation
Diffstat:
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig
@@ -419,6 +419,7 @@ pub const F = struct {
pub const DUP2FD = 10;
pub const DUPFD_CLOEXEC = 17;
pub const DUP2FD_CLOEXEC = 18;
+ pub const GETPATH = 19;
};
pub const FD_CLOEXEC = 1;
diff --git a/lib/std/os.zig b/lib/std/os.zig
@@ -5181,6 +5181,20 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
return error.InvalidHandle;
}
},
+ .dragonfly => {
+ if (comptime builtin.os.version_range.semver.max.order(.{ .major = 6, .minor = 0 }) == .lt) {
+ @compileError("querying for canonical path of a handle is unsupported on this host");
+ }
+ @memset(out_buffer, 0, MAX_PATH_BYTES);
+ switch (errno(system.fcntl(fd, F.GETPATH, out_buffer))) {
+ .SUCCESS => {},
+ .BADF => return error.FileNotFound,
+ .RANGE => return error.NameTooLong,
+ else => |err| return unexpectedErrno(err),
+ }
+ const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
+ return out_buffer[0..len];
+ },
else => @compileError("querying for canonical path of a handle is unsupported on this host"),
}
}