dragonfly: getFdPath: F_GETPATH implementation

This commit is contained in:
Michael Dusan 2023-01-02 19:18:33 -05:00
parent 7f012eef0b
commit 7da9348637
No known key found for this signature in database
GPG key ID: ED4C5BA849FA1B74
2 changed files with 15 additions and 0 deletions

View file

@ -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;

View file

@ -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"),
}
}