1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:37:35 +00:00

Kernel+LibC+LibCore+UserspaceEmulator: Implement faccessat(2)

Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
This commit is contained in:
sin-ack 2022-10-01 12:24:56 +00:00 committed by Andrew Kaster
parent fa692e13f9
commit 2a502fe232
13 changed files with 89 additions and 39 deletions

View file

@ -798,12 +798,20 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html
int access(char const* pathname, int mode)
{
return faccessat(AT_FDCWD, pathname, mode, 0);
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/faccessat.html
int faccessat(int dirfd, char const* pathname, int mode, int flags)
{
if (!pathname) {
errno = EFAULT;
return -1;
}
int rc = syscall(SC_access, pathname, strlen(pathname), mode);
Syscall::SC_faccessat_params params { dirfd, { pathname, strlen(pathname) }, mode, flags };
int rc = syscall(SC_faccessat, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}

View file

@ -104,6 +104,7 @@ int pipe(int pipefd[2]);
int pipe2(int pipefd[2], int flags);
unsigned int alarm(unsigned int seconds);
int access(char const* pathname, int mode);
int faccessat(int dirfd, char const* pathname, int mode, int flags);
int isatty(int fd);
int mknod(char const* pathname, mode_t, dev_t);
long fpathconf(int fd, int name);

View file

@ -1372,7 +1372,13 @@ ErrorOr<void> access(StringView pathname, int mode)
return Error::from_syscall("access"sv, -EFAULT);
#ifdef AK_OS_SERENITY
int rc = ::syscall(Syscall::SC_access, pathname.characters_without_null_termination(), pathname.length(), mode);
Syscall::SC_faccessat_params params {
.dirfd = AT_FDCWD,
.pathname = { pathname.characters_without_null_termination(), pathname.length() },
.mode = mode,
.flags = 0,
};
int rc = ::syscall(Syscall::SC_faccessat, &params);
HANDLE_SYSCALL_RETURN_VALUE("access", rc, {});
#else
DeprecatedString path_string = pathname;