authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 02:38:37 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 02:38:37 -07:00
logfaee6e5d1569075cf148744c95bd532b69c43028
treea9911bb4b02e601d651ad3e281ff3303feec883d
parentb47a28b8a90555bf58929546fea3b043905ae808

it's alive!


6 files changed, 90 insertions(+), 0 deletions(-)

Dir.zig created+21
......@@ -0,0 +1,21 @@
1const std = @import("std");
2const sys_libc = @import("sys-libc");
3
4const nfs = @import("./nfs.zig");
5const File = nfs.File;
6const Dir = @This();
7
8fd: nfs.Handle,
9
10pub fn close(self: Dir) void {
11 sys_libc.close(self.fd) catch {};
12}
13
14pub fn openFile(self: Dir, sub_path: [:0]const u8, flags: OpenFileFlags) !File {
15 _ = flags;
16 return .{ .fd = @enumFromInt(try sys_libc.openat(@intFromEnum(self.fd), sub_path.ptr, sys_libc.O.RDONLY)) };
17}
18
19pub const OpenFileFlags = packed struct {
20 //
21};
File.zig created+39
......@@ -0,0 +1,39 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const sys_libc = @import("sys-libc");
4const nio = @import("nio");
5const errno = @import("errno");
6
7const nfs = @import("./nfs.zig");
8const Dir = nfs.Dir;
9const File = @This();
10
11fd: nfs.Handle,
12
13pub fn close(self: File) void {
14 sys_libc.close(@intFromEnum(self.fd)) catch {};
15}
16
17pub const ReadError = switch (builtin.target.os.tag) {
18 .linux,
19 => errno.Error,
20 else => @compileError("TODO"),
21};
22pub usingnamespace nio.Readable(@This());
23pub fn read(self: File, buffer: []u8) ReadError!usize {
24 return sys_libc.read(@intFromEnum(self.fd), buffer);
25}
26
27pub fn anyReadable(self: File) nio.AnyReadable {
28 const S = struct {
29 fn foo(s: *anyopaque, buffer: []u8) anyerror!usize {
30 const fd: nfs.Handle = @enumFromInt(@intFromPtr(s));
31 const f: File = .{ .fd = fd };
32 return f.read(buffer);
33 }
34 };
35 return .{
36 .readFn = S.foo,
37 .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))),
38 };
39}
README.md+2
......@@ -7,3 +7,5 @@
77[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)
88
99Nektro's Filesystem, an alternative to `std.fs`.
10
11Some code ported from Zig 0.14.1, via MIT Copyright (c) Zig contributors. New code MPL-2.0.
licenses.txt+10
......@@ -1,3 +1,13 @@
11MPL-2.0:
22= https://spdx.org/licenses/MPL-2.0
33- This
4- git https://github.com/nektro/zig-nio
5
6MIT:
7= https://spdx.org/licenses/MIT
8- git https://github.com/nektro/zig-errno
9- git https://github.com/nektro/zig-libc
10- git https://github.com/nektro/zig-sys-libc
11
12Unspecified:
13- system_lib c
nfs.zig+15
......@@ -1 +1,16 @@
11const std = @import("std");
2const builtin = @import("builtin");
3const sys_libc = @import("sys-libc");
4
5pub const Dir = @import("./Dir.zig");
6pub const File = @import("./File.zig");
7
8pub const Handle = switch (builtin.target.os.tag) {
9 .linux,
10 => enum(c_int) { _ },
11 else => @compileError("TODO"),
12};
13
14pub fn cwd() Dir {
15 return .{ .fd = @enumFromInt(sys_libc.AT.FDCWD) };
16}
zigmod.yml+3
......@@ -6,3 +6,6 @@ description: Nektro's Filesystem, an alternative to std.fs
66min_zig_version: 0.14.0
77min_zigmod_version: r96
88dependencies:
9 - src: git https://github.com/nektro/zig-sys-libc
10 - src: git https://github.com/nektro/zig-nio
11 - src: git https://github.com/nektro/zig-errno