Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/std/fs/Dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2707,18 +2707,23 @@ pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
&stx,
);

return switch (linux.E.init(rc)) {
.SUCCESS => Stat.fromLinux(stx),
.ACCES => error.AccessDenied,
switch (linux.E.init(rc)) {
.SUCCESS => return Stat.fromLinux(stx),
.ACCES => return error.AccessDenied,
.BADF => unreachable,
.FAULT => unreachable,
.INVAL => unreachable,
.LOOP => error.SymLinkLoop,
.LOOP => return error.SymLinkLoop,
.NAMETOOLONG => unreachable, // Handled by posix.toPosixPath() above.
.NOENT, .NOTDIR => error.FileNotFound,
.NOMEM => error.SystemResources,
else => |err| posix.unexpectedErrno(err),
};
.NOENT, .NOTDIR => return error.FileNotFound,
.NOSYS => {
// riscv32 and loongarch have not implement fstatat and will not reach here
if (builtin.cpu.arch == .riscv32 or builtin.cpu.arch.isLoongArch()) unreachable;
// fallback to posix fstatat
},
.NOMEM => return error.SystemResources,
else => |err| return posix.unexpectedErrno(err),
}
}
const st = try posix.fstatat(self.fd, sub_path, 0);
return Stat.fromPosix(st);
Expand Down
15 changes: 10 additions & 5 deletions lib/std/fs/File.zig
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,24 @@ pub fn stat(self: File) StatError!Stat {
&stx,
);

return switch (linux.E.init(rc)) {
.SUCCESS => Stat.fromLinux(stx),
switch (linux.E.init(rc)) {
.SUCCESS => return Stat.fromLinux(stx),
.ACCES => unreachable,
.BADF => unreachable,
.FAULT => unreachable,
.INVAL => unreachable,
.LOOP => unreachable,
.NAMETOOLONG => unreachable,
.NOENT => unreachable,
.NOMEM => error.SystemResources,
.NOMEM => return error.SystemResources,
.NOSYS => {
// riscv32 and loongarch have not implement fstatat and will not reach here
if (builtin.cpu.arch == .riscv32 or builtin.cpu.arch.isLoongArch()) unreachable;
// fallback to posix fstatat
},
.NOTDIR => unreachable,
else => |err| posix.unexpectedErrno(err),
};
else => |err| return posix.unexpectedErrno(err),
}
}

const st = try posix.fstat(self.handle);
Expand Down