hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 8e87bce4bf91e0934563ed53f4ea0cd364dbead7
parent db101ad0e84bd70e8d60c4196062410c4e7c9f3e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  9 Mar 2021 20:29:44 -0500

rt: add fallbacks for newer syscalls

Diffstat:
Mrt/+linux/syscalls.ha | 28++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -49,6 +49,14 @@ export fn open(path: path, flags: int, mode: uint) (int | errno) = { path: uintptr: u64, flags: u64, mode: u64))?: int; }; +fn openat( + dirfd: int, + path: *const char, + flags: int, + mode: uint, +) (int | errno) = wrap_return(syscall4(SYS_openat, dirfd: u64, + path: uintptr: u64, flags: u64, mode: u64))?: int; + export fn openat2( dirfd: int, path: path, @@ -56,8 +64,7 @@ export fn openat2( how_sz: size, ) (int | errno) = { let path = kpath(path)?; - return wrap_return(syscall4(SYS_openat2, dirfd: u64, - path: uintptr: u64, how: uintptr: u64, how_sz: u64))?: int; + return openat(dirfd, path, how.flags: int, how.mode: uint); }; export fn unlink(path: path) (void | errno) = { @@ -205,6 +212,20 @@ export fn lseek(fd: int, off: i64, whence: uint) (i64 | errno) = { fd: u64, off: u64, whence: u64))?: i64; }; +fn faccessat1(dirfd: int, path: *const char, mode: int) (bool | errno) = { + return match (wrap_return(syscall3(SYS_faccessat, dirfd: u64, + path: uintptr: u64, mode: u64))) { + err: errno => switch (err) { + EACCES => false, + * => err, + }, + n: u64 => { + assert(n == 0); + true; + }, + }; +}; + // The use of this function is discouraged, as it can create race conditions. // TOCTOU is preferred: attempt to simply use the resource you need and handle // any access errors which occur. @@ -219,6 +240,9 @@ export fn faccessat( path: uintptr: u64, mode: u64, flags: u64))) { err: errno => switch (err) { EACCES => false, + ENOSYS => + if (flags == 0) faccessat1(dirfd, path, mode) + else err, * => err, }, n: u64 => {