authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 22:18:51 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-24 22:18:51 -07:00
log59ffaf7611ec0b535d172f8faacb5a769667bb02
treef7dbabc948784cf4db083e885cd8033e965aa806
parentbd1528faf2504118937f962da93c4007a229e91c

add File.stat


3 files changed, 45 insertions(+), 0 deletions(-)

File.zig+43
...@@ -3,6 +3,7 @@ const builtin = @import("builtin");...@@ -3,6 +3,7 @@ const builtin = @import("builtin");
3const sys_libc = @import("sys-libc");3const sys_libc = @import("sys-libc");
4const nio = @import("nio");4const nio = @import("nio");
5const errno = @import("errno");5const errno = @import("errno");
6const time = @import("time");
67
7const nfs = @import("./nfs.zig");8const nfs = @import("./nfs.zig");
8const Dir = nfs.Dir;9const Dir = nfs.Dir;
...@@ -37,3 +38,45 @@ pub fn anyReadable(self: File) nio.AnyReadable {...@@ -37,3 +38,45 @@ pub fn anyReadable(self: File) nio.AnyReadable {
37 .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))),38 .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))),
38 };39 };
39}40}
41
42pub fn stat(self: File) !Stat {
43 const st = try sys_libc.fstat(@intFromEnum(self.fd));
44 return .{
45 .inode = st.ino,
46 .size = @bitCast(st.size),
47 .mode = st.mode,
48 .kind = {},
49 .atime = @as(i128, st.atim.sec) * time.ns_per_s + st.atim.nsec,
50 .mtime = @as(i128, st.mtim.sec) * time.ns_per_s + st.mtim.nsec,
51 .ctime = @as(i128, st.ctim.sec) * time.ns_per_s + st.ctim.nsec,
52 };
53}
54
55pub const Stat = struct {
56 inode: INode,
57 size: u64,
58 mode: Mode,
59 kind: void, //Kind,
60 /// Last access time in nanoseconds, relative to UTC 1970-01-01.
61 atime: i128,
62 /// Last modification time in nanoseconds, relative to UTC 1970-01-01.
63 mtime: i128,
64 /// Last status/metadata change time in nanoseconds, relative to UTC 1970-01-01.
65 ctime: i128,
66};
67
68pub const INode = switch (builtin.target.os.tag) {
69 .linux,
70 => sys_libc.ino_t,
71 else => |v| @compileError("TODO: " ++ @tagName(v)),
72};
73
74pub const Mode = switch (builtin.target.os.tag) {
75 .linux,
76 => sys_libc.mode_t,
77 else => |v| @compileError("TODO: " ++ @tagName(v)),
78};
79
80pub const Kind = enum {
81 //
82};
licenses.txt+1
...@@ -8,6 +8,7 @@ MIT:...@@ -8,6 +8,7 @@ MIT:
8- git https://github.com/nektro/zig-errno8- git https://github.com/nektro/zig-errno
9- git https://github.com/nektro/zig-libc9- git https://github.com/nektro/zig-libc
10- git https://github.com/nektro/zig-sys-libc10- git https://github.com/nektro/zig-sys-libc
11- git https://github.com/nektro/zig-time
1112
12Unspecified:13Unspecified:
13- system_lib c14- system_lib c
zigmod.yml+1
...@@ -9,3 +9,4 @@ dependencies:...@@ -9,3 +9,4 @@ dependencies:
9 - src: git https://github.com/nektro/zig-sys-libc9 - src: git https://github.com/nektro/zig-sys-libc
10 - src: git https://github.com/nektro/zig-nio10 - src: git https://github.com/nektro/zig-nio
11 - src: git https://github.com/nektro/zig-errno11 - src: git https://github.com/nektro/zig-errno
12 - src: git https://github.com/nektro/zig-time