options/posix: Implemented faccessat()

Signed-off-by: Dennisbonke <admin@dennisbonke.com>
This commit is contained in:
Dennisbonke 2020-04-20 18:02:34 +02:00
parent 0047a3c1d8
commit cb156e28eb
4 changed files with 25 additions and 5 deletions

View file

@ -70,6 +70,7 @@ int sys_close(int fd);
#ifndef MLIBC_BUILDING_RTDL
[[gnu::weak]] int sys_access(const char *path, int mode);
[[gnu::weak]] int sys_faccessat(int dirfd, const char *pathname, int mode, int flags);
[[gnu::weak]] int sys_dup(int fd, int flags, int *newfd);
[[gnu::weak]] int sys_dup2(int fd, int flags, int newfd);
// In contrast to the isatty() library function, the sysdep function uses return value

View file

@ -159,9 +159,17 @@ int execvp(const char *file, char *const argv[]) {
return -1;
}
int faccessat(int, const char *, int, int) {
__ensure(!"Not implemented");
__builtin_unreachable();
int faccessat(int dirfd, const char *pathname, int mode, int flags) {
if(!mlibc::sys_faccessat) {
MLIBC_MISSING_SYSDEP();
errno = ENOSYS;
return -1;
}
if(int e = mlibc::sys_faccessat(dirfd, pathname, mode, flags); e) {
errno = e;
return -1;
}
return 0;
}
int fchown(int fd, uid_t uid, gid_t gid) {

View file

@ -65,6 +65,7 @@ int posix_fallocate(int, off_t, off_t);
#define AT_SYMLINK_FOLLOW 2
#define AT_SYMLINK_NOFOLLOW 4
#define AT_REMOVEDIR 8
#define AT_EACCESS 512
#define AT_FDCWD -100

View file

@ -3682,14 +3682,20 @@ int sys_unlinkat(int fd, const char *path, int flags) {
}
int sys_access(const char *path, int mode) {
return sys_faccessat(AT_FDCWD, path, mode, 0);
}
int sys_faccessat(int dirfd, const char *pathname, int mode, int flags) {
SignalGuard sguard;
HelAction actions[3];
globalQueue.trim();
managarm::posix::CntRequest<MemoryAllocator> req(getSysdepsAllocator());
req.set_request_type(managarm::posix::CntReqType::ACCESS);
req.set_path(frg::string<MemoryAllocator>(getSysdepsAllocator(), path));
req.set_request_type(managarm::posix::CntReqType::ACCESSAT);
req.set_path(frg::string<MemoryAllocator>(getSysdepsAllocator(), pathname));
req.set_fd(dirfd);
req.set_flags(flags);
frg::string<MemoryAllocator> ser(getSysdepsAllocator());
req.SerializeToString(&ser);
@ -3717,6 +3723,10 @@ int sys_access(const char *path, int mode) {
resp.ParseFromArray(recv_resp->data, recv_resp->length);
if(resp.error() == managarm::posix::Errors::FILE_NOT_FOUND) {
return ENOENT;
}else if(resp.error() == managarm::posix::Errors::NO_SUCH_FD) {
return EBADF;
}else if(resp.error() == managarm::fs::Errors::ILLEGAL_ARGUMENT) {
return EINVAL;
}else{
__ensure(resp.error() == managarm::posix::Errors::SUCCESS);
return 0;