authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 14:45:41-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 19:58:56-08:00
log6dcf95139118ec7e91222f7e15f5ea07a51c67f3
tree31e62b1a3b32371f4faa33e3a25b5fedd14ed1b5
parent2e9415d8a0645adbfcce6e9dc7f6bbf6be233b6f

std.Io.Threaded: error instead of assert for statx

when statx fails to return some of the requested fields

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

lib/std/Io/Threaded.zig+11-10
...@@ -2086,6 +2086,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 {...@@ -2086,6 +2086,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 {
2086 switch (linux.errno(linux.statx(file.handle, "", linux.AT.EMPTY_PATH, .{ .SIZE = true }, &statx))) {2086 switch (linux.errno(linux.statx(file.handle, "", linux.AT.EMPTY_PATH, .{ .SIZE = true }, &statx))) {
2087 .SUCCESS => {2087 .SUCCESS => {
2088 current_thread.endSyscall();2088 current_thread.endSyscall();
2089 if (!statx.mask.SIZE) return error.Unexpected;
2089 return statx.size;2090 return statx.size;
2090 },2091 },
2091 .INTR => {2092 .INTR => {
...@@ -5431,7 +5432,7 @@ fn fchmodatFallback(...@@ -5431,7 +5432,7 @@ fn fchmodatFallback(
5431 switch (sys.errno(sys.statx(path_fd, "", posix.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) {5432 switch (sys.errno(sys.statx(path_fd, "", posix.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) {
5432 .SUCCESS => {5433 .SUCCESS => {
5433 current_thread.endSyscall();5434 current_thread.endSyscall();
5434 assert(statx.mask.TYPE);5435 if (!statx.mask.TYPE) return error.Unexpected;
5435 break statx.mode;5436 break statx.mode;
5436 },5437 },
5437 .INTR => {5438 .INTR => {
...@@ -11112,15 +11113,15 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {...@@ -11112,15 +11113,15 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
11112 };11113 };
11113}11114}
1111411115
11115fn statFromLinux(stx: *const std.os.linux.Statx) File.Stat {11116fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
11116 assert(stx.mask.TYPE);11117 if (!stx.mask.TYPE) return error.Unexpected;
11117 assert(stx.mask.MODE);11118 if (!stx.mask.MODE) return error.Unexpected;
11118 assert(stx.mask.ATIME);11119 if (!stx.mask.ATIME) return error.Unexpected;
11119 assert(stx.mask.MTIME);11120 if (!stx.mask.MTIME) return error.Unexpected;
11120 assert(stx.mask.CTIME);11121 if (!stx.mask.CTIME) return error.Unexpected;
11121 assert(stx.mask.INO);11122 if (!stx.mask.INO) return error.Unexpected;
11122 assert(stx.mask.SIZE);11123 if (!stx.mask.SIZE) return error.Unexpected;
11123 assert(stx.mask.NLINK);11124 if (!stx.mask.NLINK) return error.Unexpected;
11124 const atime = stx.atime;11125 const atime = stx.atime;
11125 const mtime = stx.mtime;11126 const mtime = stx.mtime;
11126 const ctime = stx.ctime;11127 const ctime = stx.ctime;