authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-01-02 19:18:33-05:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2023-01-02 19:18:33-05:00
log7da9348637f82ca75e1100a2fce2d368f96b589f
treef038cc0d283cd2ec5c19e98845a1912543abeed6
parent7f012eef0b7bd4dbccf796c2889495150f996fba
signature Commit is signed but in an unrecognized format.

dragonfly: getFdPath: F_GETPATH implementation


2 files changed, 15 insertions(+), 0 deletions(-)

lib/std/c/dragonfly.zig+1
...@@ -419,6 +419,7 @@ pub const F = struct {...@@ -419,6 +419,7 @@ pub const F = struct {
419 pub const DUP2FD = 10;419 pub const DUP2FD = 10;
420 pub const DUPFD_CLOEXEC = 17;420 pub const DUPFD_CLOEXEC = 17;
421 pub const DUP2FD_CLOEXEC = 18;421 pub const DUP2FD_CLOEXEC = 18;
422 pub const GETPATH = 19;
422};423};
423424
424pub const FD_CLOEXEC = 1;425pub const FD_CLOEXEC = 1;
lib/std/os.zig+14
...@@ -5181,6 +5181,20 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {...@@ -5181,6 +5181,20 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
5181 return error.InvalidHandle;5181 return error.InvalidHandle;
5182 }5182 }
5183 },5183 },
5184 .dragonfly => {
5185 if (comptime builtin.os.version_range.semver.max.order(.{ .major = 6, .minor = 0 }) == .lt) {
5186 @compileError("querying for canonical path of a handle is unsupported on this host");
5187 }
5188 @memset(out_buffer, 0, MAX_PATH_BYTES);
5189 switch (errno(system.fcntl(fd, F.GETPATH, out_buffer))) {
5190 .SUCCESS => {},
5191 .BADF => return error.FileNotFound,
5192 .RANGE => return error.NameTooLong,
5193 else => |err| return unexpectedErrno(err),
5194 }
5195 const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
5196 return out_buffer[0..len];
5197 },
5184 else => @compileError("querying for canonical path of a handle is unsupported on this host"),5198 else => @compileError("querying for canonical path of a handle is unsupported on this host"),
5185 }5199 }
5186}5200}