From a916bc7fdd3975a9e2ef13c44f814c71ce017193 Mon Sep 17 00:00:00 2001 From: Archit Gupta Date: Wed, 30 Oct 2024 22:25:34 -0700 Subject: [PATCH] std.fs.File: Fix metadata error check on Linux On Linux, File.metadata calls the statx syscall directly. As such, the return value is the error code. Previously, it handled the error with `posix.errno`, which when libc is linked, treats the return value as a value set to -1 if there is an error with the error code in errno. If libc wasn't linked, it would be handled correctly. In the Linux with libc linked case, this would cause the error result to always be treated as success (err val != -1), even when an error occurred. --- lib/std/fs/File.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 36e7999bf7..68dc6360a8 100644 --- a/lib/std/fs/File.zig +++ b/lib/std/fs/File.zig @@ -1072,7 +1072,7 @@ pub fn metadata(self: File) MetadataError!Metadata { &stx, ); - switch (posix.errno(rc)) { + switch (linux.E.init(rc)) { .SUCCESS => {}, .ACCES => unreachable, .BADF => unreachable,