aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-26 14:52:14 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-26 19:58:56 -0800
commiteb29737d5d77b195b1e030e6bcb99ed0e30ede33 (patch)
tree5d208969bc75d36e82e4f16492d8b317984dcf6f /lib/std
parent6dcf95139118ec7e91222f7e15f5ea07a51c67f3 (diff)
downloadzig-eb29737d5d77b195b1e030e6bcb99ed0e30ede33.tar.gz
zig-eb29737d5d77b195b1e030e6bcb99ed0e30ede33.zip
std.Io.Threaded: more efficient statx mask check
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Io/Threaded.zig58
1 files changed, 17 insertions, 41 deletions
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
index c5e0415ad1..d9bc6e0d1a 100644
--- a/lib/std/Io/Threaded.zig
+++ b/lib/std/Io/Threaded.zig
@@ -1919,23 +1919,7 @@ fn dirStatFileLinux(
try current_thread.beginSyscall();
while (true) {
var statx = std.mem.zeroes(linux.Statx);
- const rc = sys.statx(
- dir.handle,
- sub_path_posix,
- flags,
- .{
- .TYPE = true,
- .MODE = true,
- .ATIME = true,
- .MTIME = true,
- .CTIME = true,
- .INO = true,
- .SIZE = true,
- .NLINK = true,
- },
- &statx,
- );
- switch (sys.errno(rc)) {
+ switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_mask, &statx))) {
.SUCCESS => {
current_thread.endSyscall();
return statFromLinux(&statx);
@@ -2170,22 +2154,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
try current_thread.beginSyscall();
while (true) {
var statx = std.mem.zeroes(linux.Statx);
- switch (sys.errno(sys.statx(
- file.handle,
- "",
- linux.AT.EMPTY_PATH,
- .{
- .TYPE = true,
- .MODE = true,
- .ATIME = true,
- .MTIME = true,
- .CTIME = true,
- .INO = true,
- .SIZE = true,
- .NLINK = true,
- },
- &statx,
- ))) {
+ switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_mask, &statx))) {
.SUCCESS => {
current_thread.endSyscall();
return statFromLinux(&statx);
@@ -11113,15 +11082,22 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
};
}
+const linux_statx_mask: std.os.linux.STATX = .{
+ .TYPE = true,
+ .MODE = true,
+ .ATIME = true,
+ .MTIME = true,
+ .CTIME = true,
+ .INO = true,
+ .SIZE = true,
+ .NLINK = true,
+};
+
fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
- if (!stx.mask.TYPE) return error.Unexpected;
- if (!stx.mask.MODE) return error.Unexpected;
- if (!stx.mask.ATIME) return error.Unexpected;
- if (!stx.mask.MTIME) return error.Unexpected;
- if (!stx.mask.CTIME) return error.Unexpected;
- if (!stx.mask.INO) return error.Unexpected;
- if (!stx.mask.SIZE) return error.Unexpected;
- if (!stx.mask.NLINK) return error.Unexpected;
+ const actual_mask_int: u32 = @bitCast(stx.mask);
+ const wanted_mask_int: u32 = @bitCast(linux_statx_mask);
+ if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;
+
const atime = stx.atime;
const mtime = stx.mtime;
const ctime = stx.ctime;