authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-12-28 22:15:54 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-12-28 22:15:54 -08:00
log67e61e7f59305835b3846e530b35c0823b3678a6
tree119aecfbb16dbc36cd71019a47297e31157a6a80
parent343b29cf587842ffa5874abd405bdb97b6c8649d

File.Stat: add fromPosix method


1 files changed, 24 insertions(+), 21 deletions(-)

File.zig+24-21
......@@ -46,27 +46,7 @@ pub fn anyReadable(self: File) nio.AnyReadable {
4646
4747pub fn stat(self: File) !Stat {
4848 if (os != .linux) @compileError("TODO: File.stat");
49 const st = try sys_linux.fstat(@intFromEnum(self.fd));
50 if (builtin.target.cpu.arch.isMIPS64()) {
51 return .{
52 .inode = st.ino,
53 .size = @bitCast(st.size),
54 .mode = st.mode,
55 .kind = {},
56 .atime = @as(i128, st.atim) * time.ns_per_s + st.atim_nsec,
57 .mtime = @as(i128, st.mtim) * time.ns_per_s + st.mtim_nsec,
58 .ctime = @as(i128, st.ctim) * time.ns_per_s + st.ctim_nsec,
59 };
60 }
61 return .{
62 .inode = st.ino,
63 .size = @bitCast(st.size),
64 .mode = st.mode,
65 .kind = {},
66 .atime = @as(i128, st.atim.sec) * time.ns_per_s + st.atim.nsec,
67 .mtime = @as(i128, st.mtim.sec) * time.ns_per_s + st.mtim.nsec,
68 .ctime = @as(i128, st.ctim.sec) * time.ns_per_s + st.ctim.nsec,
69 };
49 return .fromPosix(try sys_linux.fstat(@intFromEnum(self.fd)));
7050}
7151
7252pub fn getEndPos(self: File) !u64 {
......@@ -117,6 +97,29 @@ pub const Stat = struct {
11797 mtime: i128,
11898 /// Last status/metadata change time in nanoseconds, relative to UTC 1970-01-01.
11999 ctime: i128,
100
101 pub fn fromPosix(st: sys_linux.struct_stat) Stat {
102 if (os == .linux) {
103 if (builtin.target.cpu.arch.isMIPS64()) {
104 return .{
105 .inode = st.ino,
106 .size = @bitCast(st.size),
107 .mode = st.mode,
108 .atime = @as(i128, st.atim) * time.ns_per_s + st.atim_nsec,
109 .mtime = @as(i128, st.mtim) * time.ns_per_s + st.mtim_nsec,
110 .ctime = @as(i128, st.ctim) * time.ns_per_s + st.ctim_nsec,
111 };
112 }
113 return .{
114 .inode = st.ino,
115 .size = @bitCast(st.size),
116 .mode = st.mode,
117 .atime = @as(i128, st.atim.sec) * time.ns_per_s + st.atim.nsec,
118 .mtime = @as(i128, st.mtim.sec) * time.ns_per_s + st.mtim.nsec,
119 .ctime = @as(i128, st.ctim.sec) * time.ns_per_s + st.ctim.nsec,
120 };
121 }
122 }
120123};
121124
122125pub const INode = switch (builtin.target.os.tag) {