| ... | @@ -17,14 +17,12 @@ fd: nfs.Handle, | ... | @@ -17,14 +17,12 @@ fd: nfs.Handle, |
| 17 | | 17 | |
| 18 | // Resource allocation may fail; resource deallocation must succeed. | 18 | // Resource allocation may fail; resource deallocation must succeed. |
| 19 | pub fn close(self: Dir) void { | 19 | pub fn close(self: Dir) void { |
| 20 | if (os == .linux) | 20 | return sys.close(@intFromEnum(self.fd)) catch {}; |
| 21 | sys_linux.close(@intFromEnum(self.fd)) catch {}; | | |
| 22 | } | 21 | } |
| 23 | | 22 | |
| 24 | pub fn openFile(self: Dir, sub_path: [:0]const u8, flags: OpenFileFlags) !File { | 23 | pub fn openFile(self: Dir, sub_path: [:0]const u8, flags: OpenFileFlags) !File { |
| 25 | _ = flags; | 24 | _ = flags; |
| 26 | if (os == .linux) | 25 | return .{ .fd = @enumFromInt(try sys.openat(@intFromEnum(self.fd), sub_path.ptr, sys.O.RDONLY)) }; |
| 27 | return .{ .fd = @enumFromInt(try sys_linux.openat(@intFromEnum(self.fd), sub_path.ptr, sys_linux.O.RDONLY)) }; | | |
| 28 | } | 26 | } |
| 29 | | 27 | |
| 30 | pub const OpenFileFlags = packed struct { | 28 | pub const OpenFileFlags = packed struct { |
| ... | @@ -33,12 +31,11 @@ pub const OpenFileFlags = packed struct { | ... | @@ -33,12 +31,11 @@ pub const OpenFileFlags = packed struct { |
| 33 | | 31 | |
| 34 | pub fn openDir(self: Dir, sub_path: [:0]const u8, flags: OpenDirFlags) !Dir { | 32 | pub fn openDir(self: Dir, sub_path: [:0]const u8, flags: OpenDirFlags) !Dir { |
| 35 | _ = flags; | 33 | _ = flags; |
| 36 | if (os == .linux) | 34 | return .{ .fd = @enumFromInt(try sys.openat(@intFromEnum(self.fd), sub_path.ptr, sys.O.RDONLY | sys.O.DIRECTORY)) }; |
| 37 | return .{ .fd = @enumFromInt(try sys_linux.openat(@intFromEnum(self.fd), sub_path.ptr, sys_linux.O.RDONLY | sys_linux.O.DIRECTORY)) }; | | |
| 38 | } | 35 | } |
| 39 | pub fn openDirC(self: Dir, sub_path: []const u8, flags: OpenDirFlags) !Dir { | 36 | pub fn openDirC(self: Dir, sub_path: []const u8, flags: OpenDirFlags) !Dir { |
| 40 | std.debug.assert(sub_path.len <= sys_linux.NAME_MAX); | 37 | std.debug.assert(sub_path.len <= sys.NAME_MAX); |
| 41 | var buf: [sys_linux.NAME_MAX + 1]u8 = undefined; | 38 | var buf: [sys.NAME_MAX + 1]u8 = undefined; |
| 42 | @memcpy(buf[0..sub_path.len], sub_path); | 39 | @memcpy(buf[0..sub_path.len], sub_path); |
| 43 | buf[sub_path.len] = 0; | 40 | buf[sub_path.len] = 0; |
| 44 | return openDir(self, buf[0..sub_path.len :0], flags); | 41 | return openDir(self, buf[0..sub_path.len :0], flags); |
| ... | @@ -61,19 +58,17 @@ pub fn readFileAlloc(self: Dir, allocator: std.mem.Allocator, file_path: [:0]con | ... | @@ -61,19 +58,17 @@ pub fn readFileAlloc(self: Dir, allocator: std.mem.Allocator, file_path: [:0]con |
| 61 | } | 58 | } |
| 62 | | 59 | |
| 63 | pub fn makeDir(self: Dir, sub_path: [:0]const u8) !void { | 60 | pub fn makeDir(self: Dir, sub_path: [:0]const u8) !void { |
| 64 | if (os == .linux) | 61 | try sys.mkdirat(@intFromEnum(self.fd), sub_path, 0o755); |
| 65 | try sys_linux.mkdirat(@intFromEnum(self.fd), sub_path, 0o755); | | |
| 66 | } | 62 | } |
| 67 | | 63 | |
| 68 | pub fn statFile(self: Dir, sub_path: [:0]const u8) !File.Stat { | 64 | pub fn statFile(self: Dir, sub_path: [:0]const u8) !File.Stat { |
| 69 | if (os == .linux) | 65 | return .fromPosix(try sys.fstatat(@intFromEnum(self.fd), sub_path, 0)); |
| 70 | return .fromPosix(try sys_linux.fstatat(@intFromEnum(self.fd), sub_path, 0)); | | |
| 71 | } | 66 | } |
| 72 | | 67 | |
| 73 | pub fn makePath(self: Dir, sub_path: [:0]const u8) !void { | 68 | pub fn makePath(self: Dir, sub_path: [:0]const u8) !void { |
| 74 | var it = try std.fs.path.componentIterator(sub_path); | 69 | var it = try std.fs.path.componentIterator(sub_path); |
| 75 | var component = it.last() orelse return; | 70 | var component = it.last() orelse return; |
| 76 | var zuffer: [sys_linux.NAME_MAX + 1]u8 = undefined; | 71 | var zuffer: [sys.NAME_MAX + 1]u8 = undefined; |
| 77 | while (true) { | 72 | while (true) { |
| 78 | @memcpy(zuffer[0..component.path.len], component.path); | 73 | @memcpy(zuffer[0..component.path.len], component.path); |
| 79 | zuffer[component.path.len] = 0; | 74 | zuffer[component.path.len] = 0; |