Luna/libc/src/fcntl.cpp
apio 349ba0acb1
All checks were successful
continuous-integration/drone/push Build is passing
libc: Add syscall wrappers for unlinkat() and openat()
2023-05-05 18:50:35 +02:00

53 lines
1.1 KiB
C++

#include <bits/errno-return.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C"
{
int open(const char* path, int flags, ...)
{
va_list ap;
va_start(ap, flags);
mode_t mode = (mode_t)va_arg(ap, int);
long rc = syscall(SYS_openat, AT_FDCWD, path, flags, mode);
va_end(ap);
__errno_return(rc, int);
}
int openat(int dirfd, const char* path, int flags, ...)
{
va_list ap;
va_start(ap, flags);
mode_t mode = (mode_t)va_arg(ap, int);
long rc = syscall(SYS_openat, dirfd, path, flags, mode);
va_end(ap);
__errno_return(rc, int);
}
int creat(const char* path, mode_t mode)
{
return openat(AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
int fcntl(int fd, int cmd, ...)
{
va_list ap;
va_start(ap, cmd);
uintptr_t arg = (uintptr_t)va_arg(ap, uintptr_t);
long rc = syscall(SYS_fcntl, fd, cmd, arg);
va_end(ap);
__errno_return(rc, int);
}
}