Skip to content

Commit 8d9bb97

Browse files
rootbeeralexrp
authored andcommitted
posix: access/accessZ/faccessat/faccessatZ can return AccessDenied or PermissionDenied
`EACCES` is returned if the file mode bit (i.e., user/group/other rwx bits) disallow access. `EPERM` is returned if something else denies access (immutable bit, SELinux, capabilities, etc). This somewhat subtle no-access distinction is part of POSIX. For now map both to `error.PermissionDenied` to keep the error signature unchanged. See duopoly. This PR is effecitvely an update/simplification of PR #19193. Tested locally with an immutable file. Fixes #22733 and #19162.
1 parent a8d3760 commit 8d9bb97

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/std/posix.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4914,6 +4914,7 @@ pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
49144914
switch (errno(system.access(path, mode))) {
49154915
.SUCCESS => return,
49164916
.ACCES => return error.PermissionDenied,
4917+
.PERM => return error.PermissionDenied,
49174918
.ROFS => return error.ReadOnlyFileSystem,
49184919
.LOOP => return error.SymLinkLoop,
49194920
.TXTBSY => return error.FileBusy,
@@ -4999,6 +5000,7 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
49995000
switch (errno(system.faccessat(dirfd, path, mode, flags))) {
50005001
.SUCCESS => return,
50015002
.ACCES => return error.PermissionDenied,
5003+
.PERM => return error.PermissionDenied,
50025004
.ROFS => return error.ReadOnlyFileSystem,
50035005
.LOOP => return error.SymLinkLoop,
50045006
.TXTBSY => return error.FileBusy,

0 commit comments

Comments
 (0)