From be2fd8e7a40a739325faba750c606ecb8f779c00 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 15 Feb 2026 16:44:31 -0800 Subject: [PATCH] make File Writable --- File.zig | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/File.zig b/File.zig index ac7312e35fecde10958220dc60bfd1ae63ba8787..81e706d0e78ce51898e9abde30a58152b25225ee 100644 --- a/File.zig +++ b/File.zig @@ -10,6 +10,11 @@ const File = @This(); const os = builtin.target.os.tag; +const sys = switch (os) { + .linux => sys_linux, + else => unreachable, +}; + fd: nfs.Handle, // 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 } } +pub const WriteError = sys.errno.Error; +pub usingnamespace nio.Writable(@This(), ._bare); +pub fn write(self: File, buffer: []const u8) WriteError!usize { + return sys.write(@intFromEnum(self.fd), buffer); +} + pub const Stat = struct { inode: INode, size: u64, @@ -137,14 +148,12 @@ pub const Stat = struct { }; pub const INode = switch (builtin.target.os.tag) { - .linux, - => sys_linux.ino_t, + .linux => sys_linux.ino_t, else => |v| @compileError("TODO: " ++ @tagName(v)), }; pub const Mode = switch (builtin.target.os.tag) { - .linux, - => sys_linux.mode_t, + .linux => sys_linux.mode_t, else => |v| @compileError("TODO: " ++ @tagName(v)), }; -- 2.54.0