diff --git a/lib/std/c/dragonfly.zig b/lib/std/c/dragonfly.zig index 2410310fc7..bfe7806c14 100644 --- 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 index 0394e50389..f096d1920b 100644 --- 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"), } }