| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | | const sys_linux = @import("sys-linux"); |
| 4 | 3 | const nio = @import("nio"); |
| 5 | 4 | const time = @import("time"); |
| 6 | 5 | |
| ... | ... | @@ -11,7 +10,7 @@ const File = @This(); |
| 11 | 10 | const os = builtin.target.os.tag; |
| 12 | 11 | |
| 13 | 12 | const sys = switch (os) { |
| 14 | | .linux => sys_linux, |
| 13 | .linux => @import("sys-linux"), |
| 15 | 14 | else => unreachable, |
| 16 | 15 | }; |
| 17 | 16 | |
| ... | ... | @@ -19,8 +18,7 @@ fd: nfs.Handle, |
| 19 | 18 | |
| 20 | 19 | // Resource allocation may fail; resource deallocation must succeed. |
| 21 | 20 | pub fn close(self: File) void { |
| 22 | | if (os == .linux) |
| 23 | | sys_linux.close(@intFromEnum(self.fd)) catch {}; |
| 21 | sys.close(@intFromEnum(self.fd)) catch {}; |
| 24 | 22 | } |
| 25 | 23 | |
| 26 | 24 | const R = nio.Readable(@This(), ._bare); |
| ... | ... | @@ -38,13 +36,9 @@ pub const readAlloc = R.readAlloc; |
| 38 | 36 | pub const readInt = R.readInt; |
| 39 | 37 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 40 | 38 | |
| 41 | | pub const ReadError = switch (builtin.target.os.tag) { |
| 42 | | .linux => sys_linux.errno.Error, |
| 43 | | else => @compileError("TODO"), |
| 44 | | }; |
| 39 | pub const ReadError = sys.errno.Error; |
| 45 | 40 | pub fn read(self: File, buffer: []u8) ReadError!usize { |
| 46 | | if (os == .linux) |
| 47 | | return sys_linux.read(@intFromEnum(self.fd), buffer); |
| 41 | return sys.read(@intFromEnum(self.fd), buffer); |
| 48 | 42 | } |
| 49 | 43 | |
| 50 | 44 | pub fn anyReadable(self: File) nio.AnyReadable { |
| ... | ... | @@ -62,8 +56,7 @@ pub fn anyReadable(self: File) nio.AnyReadable { |
| 62 | 56 | } |
| 63 | 57 | |
| 64 | 58 | pub fn stat(self: File) !Stat { |
| 65 | | if (os != .linux) @compileError("TODO: File.stat"); |
| 66 | | return .fromPosix(try sys_linux.fstat(@intFromEnum(self.fd))); |
| 59 | return .fromPosix(try sys.fstat(@intFromEnum(self.fd))); |
| 67 | 60 | } |
| 68 | 61 | |
| 69 | 62 | pub fn getEndPos(self: File) !u64 { |
| ... | ... | @@ -132,7 +125,7 @@ pub const Stat = struct { |
| 132 | 125 | /// Last status/metadata change time in nanoseconds, relative to UTC 1970-01-01. |
| 133 | 126 | ctime: i128, |
| 134 | 127 | |
| 135 | | pub fn fromPosix(st: sys_linux.struct_stat) Stat { |
| 128 | pub fn fromPosix(st: sys.struct_stat) Stat { |
| 136 | 129 | if (os == .linux) { |
| 137 | 130 | if (builtin.target.cpu.arch.isMIPS64()) { |
| 138 | 131 | return .{ |
| ... | ... | @@ -156,32 +149,24 @@ pub const Stat = struct { |
| 156 | 149 | } |
| 157 | 150 | |
| 158 | 151 | pub fn kind(self: Stat) Kind { |
| 159 | | if (os == .linux) { |
| 160 | | const m = self.mode & sys_linux.S.IFMT; |
| 161 | | switch (m) { |
| 162 | | sys_linux.S.IFBLK => return .block_device, |
| 163 | | sys_linux.S.IFCHR => return .character_device, |
| 164 | | sys_linux.S.IFIFO => return .named_pipe, |
| 165 | | sys_linux.S.IFREG => return .file, |
| 166 | | sys_linux.S.IFDIR => return .directory, |
| 167 | | sys_linux.S.IFLNK => return .symlink, |
| 168 | | sys_linux.S.IFSOCK => return .unix_socket, |
| 169 | | else => {}, |
| 170 | | } |
| 171 | | return .unknown; |
| 152 | const m = self.mode & sys.S.IFMT; |
| 153 | switch (m) { |
| 154 | sys.S.IFBLK => return .block_device, |
| 155 | sys.S.IFCHR => return .character_device, |
| 156 | sys.S.IFIFO => return .named_pipe, |
| 157 | sys.S.IFREG => return .file, |
| 158 | sys.S.IFDIR => return .directory, |
| 159 | sys.S.IFLNK => return .symlink, |
| 160 | sys.S.IFSOCK => return .unix_socket, |
| 161 | else => {}, |
| 172 | 162 | } |
| 163 | return .unknown; |
| 173 | 164 | } |
| 174 | 165 | }; |
| 175 | 166 | |
| 176 | | pub const INode = switch (builtin.target.os.tag) { |
| 177 | | .linux => sys_linux.ino_t, |
| 178 | | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 179 | | }; |
| 167 | pub const INode = sys.ino_t; |
| 180 | 168 | |
| 181 | | pub const Mode = switch (builtin.target.os.tag) { |
| 182 | | .linux => sys_linux.mode_t, |
| 183 | | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 184 | | }; |
| 169 | pub const Mode = sys.mode_t; |
| 185 | 170 | |
| 186 | 171 | pub const Kind = enum { |
| 187 | 172 | block_device, |