authorgravatar for archit@accelbread.comArchit Gupta <archit@accelbread.com> 2024-10-30 22:25:34-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-31 14:02:42+01:00
loga916bc7fdd3975a9e2ef13c44f814c71ce017193
tree8242d9f1b869b0ddf2dbca8680d245eb5c9660d1
parentf2dcfe0e408e1abf0c75293d75c4d92aed033eae

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 files changed, 1 insertions(+), 1 deletions(-)

lib/std/fs/File.zig+1-1
...@@ -1072,7 +1072,7 @@ pub fn metadata(self: File) MetadataError!Metadata {...@@ -1072,7 +1072,7 @@ pub fn metadata(self: File) MetadataError!Metadata {
1072 &stx,1072 &stx,
1073 );1073 );
10741074
1075 switch (posix.errno(rc)) {1075 switch (linux.E.init(rc)) {
1076 .SUCCESS => {},1076 .SUCCESS => {},
1077 .ACCES => unreachable,1077 .ACCES => unreachable,
1078 .BADF => unreachable,1078 .BADF => unreachable,