Commit e752606464

Michael Dusan <michael.dusan@gmail.com>
2023-01-03 01:18:33
netbsd: getFdPath: F_GETPATH implementation
1 parent 1a40338
Changed files (2)
lib/std/c/netbsd.zig
@@ -690,13 +690,17 @@ pub const F = struct {
     pub const SETFD = 2;
     pub const GETFL = 3;
     pub const SETFL = 4;
-
     pub const GETOWN = 5;
     pub const SETOWN = 6;
-
     pub const GETLK = 7;
     pub const SETLK = 8;
     pub const SETLKW = 9;
+    pub const CLOSEM = 10;
+    pub const MAXFD = 11;
+    pub const DUPFD_CLOEXEC = 12;
+    pub const GETNOSIGPIPE = 13;
+    pub const SETNOSIGPIPE = 14;
+    pub const GETPATH = 15;
 
     pub const RDLCK = 1;
     pub const WRLCK = 3;
lib/std/os.zig
@@ -5195,6 +5195,23 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
             const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
             return out_buffer[0..len];
         },
+        .netbsd => {
+            if (comptime builtin.os.version_range.semver.max.order(.{ .major = 10, .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 => {},
+                .ACCES => return error.AccessDenied,
+                .BADF => return error.FileNotFound,
+                .NOENT => return error.FileNotFound,
+                .NOMEM => return error.SystemResources,
+                .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"),
     }
 }