Skip to content

Commit a916bc7

Browse files
accelbreadalexrp
authored andcommitted
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.
1 parent f2dcfe0 commit a916bc7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/std/fs/File.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ pub fn metadata(self: File) MetadataError!Metadata {
10721072
&stx,
10731073
);
10741074

1075-
switch (posix.errno(rc)) {
1075+
switch (linux.E.init(rc)) {
10761076
.SUCCESS => {},
10771077
.ACCES => unreachable,
10781078
.BADF => unreachable,

0 commit comments

Comments
 (0)