| author | |
| committer | |
| log | 9a4f8159be199f9a94d96a9cb41f4a88c592b46f |
| tree | c093c2570990a1497f0653e162ddfdd2a3301754 |
| parent | 874ae5c71c029969d4aef1aaea77b6dcbf913289 |
5 files changed, 36 insertions(+), 23 deletions(-)
Dir.zig+10-4| ... | @@ -1,19 +1,24 @@ | ... | @@ -1,19 +1,24 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const sys_libc = @import("sys-libc"); | 2 | const builtin = @import("builtin"); |
| 3 | const sys_linux = @import("sys-linux"); | ||
| 3 | 4 | ||
| 4 | const nfs = @import("./nfs.zig"); | 5 | const nfs = @import("./nfs.zig"); |
| 5 | const File = nfs.File; | 6 | const File = nfs.File; |
| 6 | const Dir = @This(); | 7 | const Dir = @This(); |
| 7 | 8 | ||
| 9 | const os = builtin.target.os.tag; | ||
| 10 | |||
| 8 | fd: nfs.Handle, | 11 | fd: nfs.Handle, |
| 9 | 12 | ||
| 10 | pub fn close(self: Dir) void { | 13 | pub fn close(self: Dir) void { |
| 11 | sys_libc.close(@intFromEnum(self.fd)) catch {}; | 14 | if (os == .linux) |
| 15 | sys_linux.close(@intFromEnum(self.fd)) catch {}; | ||
| 12 | } | 16 | } |
| 13 | 17 | ||
| 14 | pub fn openFile(self: Dir, sub_path: [:0]const u8, flags: OpenFileFlags) !File { | 18 | pub fn openFile(self: Dir, sub_path: [:0]const u8, flags: OpenFileFlags) !File { |
| 15 | _ = flags; | 19 | _ = flags; |
| 16 | return .{ .fd = @enumFromInt(try sys_libc.openat(@intFromEnum(self.fd), sub_path.ptr, sys_libc.O.RDONLY)) }; | 20 | if (os == .linux) |
| 21 | return .{ .fd = @enumFromInt(try sys_linux.openat(@intFromEnum(self.fd), sub_path.ptr, sys_linux.O.RDONLY)) }; | ||
| 17 | } | 22 | } |
| 18 | 23 | ||
| 19 | pub const OpenFileFlags = packed struct { | 24 | pub const OpenFileFlags = packed struct { |
| ... | @@ -22,7 +27,8 @@ pub const OpenFileFlags = packed struct { | ... | @@ -22,7 +27,8 @@ pub const OpenFileFlags = packed struct { |
| 22 | 27 | ||
| 23 | pub fn openDir(self: Dir, sub_path: [:0]const u8, flags: OpenDirFlags) !Dir { | 28 | pub fn openDir(self: Dir, sub_path: [:0]const u8, flags: OpenDirFlags) !Dir { |
| 24 | _ = flags; | 29 | _ = flags; |
| 25 | return .{ .fd = @enumFromInt(try sys_libc.openat(@intFromEnum(self.fd), sub_path.ptr, sys_libc.O.RDONLY | sys_libc.O.DIRECTORY)) }; | 30 | if (os == .linux) |
| 31 | return .{ .fd = @enumFromInt(try sys_linux.openat(@intFromEnum(self.fd), sub_path.ptr, sys_linux.O.RDONLY | sys_linux.O.DIRECTORY)) }; | ||
| 26 | } | 32 | } |
| 27 | 33 | ||
| 28 | pub const OpenDirFlags = packed struct { | 34 | pub const OpenDirFlags = packed struct { |
File.zig+12-8| ... | @@ -1,28 +1,31 @@ | ... | @@ -1,28 +1,31 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const sys_libc = @import("sys-libc"); | 3 | const sys_linux = @import("sys-linux"); |
| 4 | const nio = @import("nio"); | 4 | const nio = @import("nio"); |
| 5 | const errno = @import("errno"); | ||
| 6 | const time = @import("time"); | 5 | const time = @import("time"); |
| 7 | 6 | ||
| 8 | const nfs = @import("./nfs.zig"); | 7 | const nfs = @import("./nfs.zig"); |
| 9 | const Dir = nfs.Dir; | 8 | const Dir = nfs.Dir; |
| 10 | const File = @This(); | 9 | const File = @This(); |
| 11 | 10 | ||
| 11 | const os = builtin.target.os.tag; | ||
| 12 | |||
| 12 | fd: nfs.Handle, | 13 | fd: nfs.Handle, |
| 13 | 14 | ||
| 14 | pub fn close(self: File) void { | 15 | pub fn close(self: File) void { |
| 15 | sys_libc.close(@intFromEnum(self.fd)) catch {}; | 16 | if (os == .linux) |
| 17 | sys_linux.close(@intFromEnum(self.fd)) catch {}; | ||
| 16 | } | 18 | } |
| 17 | 19 | ||
| 18 | pub const ReadError = switch (builtin.target.os.tag) { | 20 | pub const ReadError = switch (builtin.target.os.tag) { |
| 19 | .linux, | 21 | .linux, |
| 20 | => errno.Error, | 22 | => sys_linux.errno.Error, |
| 21 | else => @compileError("TODO"), | 23 | else => @compileError("TODO"), |
| 22 | }; | 24 | }; |
| 23 | pub usingnamespace nio.Readable(@This(), ._bare); | 25 | pub usingnamespace nio.Readable(@This(), ._bare); |
| 24 | pub fn read(self: File, buffer: []u8) ReadError!usize { | 26 | pub fn read(self: File, buffer: []u8) ReadError!usize { |
| 25 | return sys_libc.read(@intFromEnum(self.fd), buffer); | 27 | if (os == .linux) |
| 28 | return sys_linux.read(@intFromEnum(self.fd), buffer); | ||
| 26 | } | 29 | } |
| 27 | 30 | ||
| 28 | pub fn anyReadable(self: File) nio.AnyReadable { | 31 | pub fn anyReadable(self: File) nio.AnyReadable { |
| ... | @@ -42,7 +45,8 @@ pub fn anyReadable(self: File) nio.AnyReadable { | ... | @@ -42,7 +45,8 @@ pub fn anyReadable(self: File) nio.AnyReadable { |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | pub fn stat(self: File) !Stat { | 47 | pub fn stat(self: File) !Stat { |
| 45 | const st = try sys_libc.fstat(@intFromEnum(self.fd)); | 48 | if (os != .linux) @compileError("TODO: File.stat"); |
| 49 | const st = try sys_linux.fstat(@intFromEnum(self.fd)); | ||
| 46 | return .{ | 50 | return .{ |
| 47 | .inode = st.ino, | 51 | .inode = st.ino, |
| 48 | .size = @bitCast(st.size), | 52 | .size = @bitCast(st.size), |
| ... | @@ -106,13 +110,13 @@ pub const Stat = struct { | ... | @@ -106,13 +110,13 @@ pub const Stat = struct { |
| 106 | 110 | ||
| 107 | pub const INode = switch (builtin.target.os.tag) { | 111 | pub const INode = switch (builtin.target.os.tag) { |
| 108 | .linux, | 112 | .linux, |
| 109 | => sys_libc.ino_t, | 113 | => sys_linux.ino_t, |
| 110 | else => |v| @compileError("TODO: " ++ @tagName(v)), | 114 | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 111 | }; | 115 | }; |
| 112 | 116 | ||
| 113 | pub const Mode = switch (builtin.target.os.tag) { | 117 | pub const Mode = switch (builtin.target.os.tag) { |
| 114 | .linux, | 118 | .linux, |
| 115 | => sys_libc.mode_t, | 119 | => sys_linux.mode_t, |
| 116 | else => |v| @compileError("TODO: " ++ @tagName(v)), | 120 | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 117 | }; | 121 | }; |
| 118 | 122 |
licenses.txt+1-3| ... | @@ -5,9 +5,7 @@ MPL-2.0: | ... | @@ -5,9 +5,7 @@ MPL-2.0: |
| 5 | 5 | ||
| 6 | MIT: | 6 | MIT: |
| 7 | = https://spdx.org/licenses/MIT | 7 | = https://spdx.org/licenses/MIT |
| 8 | - git https://github.com/nektro/zig-errno | 8 | - git https://github.com/nektro/zig-sys-linux |
| 9 | - git https://github.com/nektro/zig-libc | ||
| 10 | - git https://github.com/nektro/zig-sys-libc | ||
| 11 | - git https://github.com/nektro/zig-time | 9 | - git https://github.com/nektro/zig-time |
| 12 | 10 | ||
| 13 | Unspecified: | 11 | Unspecified: |
nfs.zig+12-6| ... | @@ -1,28 +1,34 @@ | ... | @@ -1,28 +1,34 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const sys_libc = @import("sys-libc"); | 3 | const sys_linux = @import("sys-linux"); |
| 4 | 4 | ||
| 5 | pub const Dir = @import("./Dir.zig"); | 5 | pub const Dir = @import("./Dir.zig"); |
| 6 | pub const File = @import("./File.zig"); | 6 | pub const File = @import("./File.zig"); |
| 7 | 7 | ||
| 8 | pub const Handle = switch (builtin.target.os.tag) { | 8 | const os = builtin.target.os.tag; |
| 9 | |||
| 10 | pub const Handle = switch (os) { | ||
| 9 | .linux, | 11 | .linux, |
| 10 | => enum(c_int) { _ }, | 12 | => enum(c_int) { _ }, |
| 11 | else => @compileError("TODO"), | 13 | else => @compileError("TODO"), |
| 12 | }; | 14 | }; |
| 13 | 15 | ||
| 14 | pub fn cwd() Dir { | 16 | pub fn cwd() Dir { |
| 15 | return .{ .fd = @enumFromInt(sys_libc.AT.FDCWD) }; | 17 | if (os == .linux) |
| 18 | return .{ .fd = @enumFromInt(sys_linux.AT.FDCWD) }; | ||
| 16 | } | 19 | } |
| 17 | 20 | ||
| 18 | pub fn stdin() File { | 21 | pub fn stdin() File { |
| 19 | return .{ .fd = @enumFromInt(0) }; | 22 | if (os == .linux) |
| 23 | return .{ .fd = @enumFromInt(0) }; | ||
| 20 | } | 24 | } |
| 21 | 25 | ||
| 22 | pub fn stdout() File { | 26 | pub fn stdout() File { |
| 23 | return .{ .fd = @enumFromInt(1) }; | 27 | if (os == .linux) |
| 28 | return .{ .fd = @enumFromInt(1) }; | ||
| 24 | } | 29 | } |
| 25 | 30 | ||
| 26 | pub fn stderr() File { | 31 | pub fn stderr() File { |
| 27 | return .{ .fd = @enumFromInt(2) }; | 32 | if (os == .linux) |
| 33 | return .{ .fd = @enumFromInt(2) }; | ||
| 28 | } | 34 | } |
zigmod.yml+1-2| ... | @@ -6,7 +6,6 @@ description: Nektro's Filesystem, an alternative to std.fs | ... | @@ -6,7 +6,6 @@ description: Nektro's Filesystem, an alternative to std.fs |
| 6 | min_zig_version: 0.14.0 | 6 | min_zig_version: 0.14.0 |
| 7 | min_zigmod_version: r96 | 7 | min_zigmod_version: r96 |
| 8 | dependencies: | 8 | dependencies: |
| 9 | - src: git https://github.com/nektro/zig-sys-libc | 9 | - src: git https://github.com/nektro/zig-sys-linux |
| 10 | - src: git https://github.com/nektro/zig-nio | 10 | - src: git https://github.com/nektro/zig-nio |
| 11 | - src: git https://github.com/nektro/zig-errno | ||
| 12 | - src: git https://github.com/nektro/zig-time | 11 | - src: git https://github.com/nektro/zig-time |