Skip to content

Commit 026c9d7

Browse files
committed
std.os: restore plain linux.faccessat syscall wrapper, only use .faccessat2 when required for flags
1 parent cf90a5e commit 026c9d7

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/std/os/linux.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,15 @@ pub fn access(path: [*:0]const u8, mode: u32) usize {
12381238
if (@hasField(SYS, "access")) {
12391239
return syscall2(.access, @intFromPtr(path), mode);
12401240
} else {
1241-
return syscall4(.faccessat, @as(usize, @bitCast(@as(isize, AT.FDCWD))), @intFromPtr(path), mode, 0);
1241+
return faccessat(AT.FDCWD, path, mode);
12421242
}
12431243
}
12441244

1245-
pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
1245+
pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {
1246+
return syscall3(.faccessat, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode);
1247+
}
1248+
1249+
pub fn faccessat2(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
12461250
return syscall4(.faccessat2, @as(usize, @bitCast(@as(isize, dirfd))), @intFromPtr(path), mode, flags);
12471251
}
12481252

lib/std/posix.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5054,7 +5054,16 @@ pub fn faccessatZ(dirfd: fd_t, path: [*:0]const u8, mode: u32, flags: u32) Acces
50545054
} else if (native_os == .wasi and !builtin.link_libc) {
50555055
return faccessat(dirfd, mem.sliceTo(path, 0), mode, flags);
50565056
}
5057-
switch (errno(system.faccessat(dirfd, path, mode, flags))) {
5057+
5058+
const need_flags = (flags != 0); //the older, simpler syscall should stay supported, so we only need to use faccessat2 if we need flags
5059+
const faccessat_result = switch (system) {
5060+
linux => if (need_flags)
5061+
linux.faccessat2(dirfd, path, mode, flags)
5062+
else
5063+
linux.faccessat(dirfd, path, mode),
5064+
else => system.faccessat(dirfd, path, mode, flags),
5065+
};
5066+
switch (errno(faccessat_result)) {
50585067
.SUCCESS => return,
50595068
.ACCES => return error.AccessDenied,
50605069
.PERM => return error.PermissionDenied,

0 commit comments

Comments
 (0)