authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 11:18:16-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-27 11:18:16-08:00
log212968c574ada30dd593dddf6d5c0cfd962459e0
tree5f64e1ba76b4f5f75e5beae8f305791a29dd5867
parentc0809c9b68ad33b9963ff3da1a6ad53ca2c8b6f3

std.Io.Threaded: handle missing atime from statx


1 files changed, 20 insertions(+), 10 deletions(-)

lib/std/Io/Threaded.zig+20-10
......@@ -1934,7 +1934,7 @@ fn dirStatFileLinux(
19341934 try current_thread.beginSyscall();
19351935 while (true) {
19361936 var statx = std.mem.zeroes(linux.Statx);
1937 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_mask, &statx))) {
1937 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_request, &statx))) {
19381938 .SUCCESS => {
19391939 current_thread.endSyscall();
19401940 return statFromLinux(&statx);
......@@ -2169,7 +2169,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
21692169 try current_thread.beginSyscall();
21702170 while (true) {
21712171 var statx = std.mem.zeroes(linux.Statx);
2172 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_mask, &statx))) {
2172 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_request, &statx))) {
21732173 .SUCCESS => {
21742174 current_thread.endSyscall();
21752175 return statFromLinux(&statx);
......@@ -11101,7 +11101,7 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
1110111101 };
1110211102}
1110311103
11104const linux_statx_mask: std.os.linux.STATX = .{
11104const linux_statx_request: std.os.linux.STATX = .{
1110511105 .TYPE = true,
1110611106 .MODE = true,
1110711107 .ATIME = true,
......@@ -11112,14 +11112,22 @@ const linux_statx_mask: std.os.linux.STATX = .{
1111211112 .NLINK = true,
1111311113};
1111411114
11115const linux_statx_check: std.os.linux.STATX = .{
11116 .TYPE = true,
11117 .MODE = true,
11118 .ATIME = false,
11119 .MTIME = true,
11120 .CTIME = true,
11121 .INO = true,
11122 .SIZE = true,
11123 .NLINK = true,
11124};
11125
1111511126fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
1111611127 const actual_mask_int: u32 = @bitCast(stx.mask);
11117 const wanted_mask_int: u32 = @bitCast(linux_statx_mask);
11128 const wanted_mask_int: u32 = @bitCast(linux_statx_check);
1111811129 if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;
1111911130
11120 const atime = stx.atime;
11121 const mtime = stx.mtime;
11122 const ctime = stx.ctime;
1112311131 return .{
1112411132 .inode = stx.ino,
1112511133 .nlink = stx.nlink,
......@@ -11135,9 +11143,11 @@ fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
1113511143 std.os.linux.S.IFSOCK => .unix_domain_socket,
1113611144 else => .unknown,
1113711145 },
11138 .atime = .{ .nanoseconds = @intCast(@as(i128, atime.sec) * std.time.ns_per_s + atime.nsec) },
11139 .mtime = .{ .nanoseconds = @intCast(@as(i128, mtime.sec) * std.time.ns_per_s + mtime.nsec) },
11140 .ctime = .{ .nanoseconds = @intCast(@as(i128, ctime.sec) * std.time.ns_per_s + ctime.nsec) },
11146 .atime = if (!stx.mask.ATIME) null else .{
11147 .nanoseconds = @intCast(@as(i128, stx.atime.sec) * std.time.ns_per_s + stx.atime.nsec),
11148 },
11149 .mtime = .{ .nanoseconds = @intCast(@as(i128, stx.mtime.sec) * std.time.ns_per_s + stx.mtime.nsec) },
11150 .ctime = .{ .nanoseconds = @intCast(@as(i128, stx.ctime.sec) * std.time.ns_per_s + stx.ctime.nsec) },
1114111151 };
1114211152}
1114311153