authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-15 16:44:31 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-02-15 16:44:31 -08:00
logbe2fd8e7a40a739325faba750c606ecb8f779c00
treea135ac22fd4cbffd011aa127394a9e56cb61f738
parent277cdf3e84c90e0f8860c9514f7609816b352a7a

make File Writable


1 files changed, 13 insertions(+), 4 deletions(-)

File.zig+13-4
...@@ -10,6 +10,11 @@ const File = @This();...@@ -10,6 +10,11 @@ const File = @This();
1010
11const os = builtin.target.os.tag;11const os = builtin.target.os.tag;
1212
13const sys = switch (os) {
14 .linux => sys_linux,
15 else => unreachable,
16};
17
13fd: nfs.Handle,18fd: nfs.Handle,
1419
15// Resource allocation may fail; resource deallocation must succeed.20// Resource allocation may fail; resource deallocation must succeed.
...@@ -84,6 +89,12 @@ pub fn readAllArrayList(self: File, array_list: *std.ArrayList(u8), max_append_s...@@ -84,6 +89,12 @@ pub fn readAllArrayList(self: File, array_list: *std.ArrayList(u8), max_append_s
84 }89 }
85}90}
8691
92pub const WriteError = sys.errno.Error;
93pub usingnamespace nio.Writable(@This(), ._bare);
94pub fn write(self: File, buffer: []const u8) WriteError!usize {
95 return sys.write(@intFromEnum(self.fd), buffer);
96}
97
87pub const Stat = struct {98pub const Stat = struct {
88 inode: INode,99 inode: INode,
89 size: u64,100 size: u64,
...@@ -137,14 +148,12 @@ pub const Stat = struct {...@@ -137,14 +148,12 @@ pub const Stat = struct {
137};148};
138149
139pub const INode = switch (builtin.target.os.tag) {150pub const INode = switch (builtin.target.os.tag) {
140 .linux,151 .linux => sys_linux.ino_t,
141 => sys_linux.ino_t,
142 else => |v| @compileError("TODO: " ++ @tagName(v)),152 else => |v| @compileError("TODO: " ++ @tagName(v)),
143};153};
144154
145pub const Mode = switch (builtin.target.os.tag) {155pub const Mode = switch (builtin.target.os.tag) {
146 .linux,156 .linux => sys_linux.mode_t,
147 => sys_linux.mode_t,
148 else => |v| @compileError("TODO: " ++ @tagName(v)),157 else => |v| @compileError("TODO: " ++ @tagName(v)),
149};158};
150159