Luna/libc/src/fcntl.cpp

53 lines
1.1 KiB
C++
Raw Normal View History

#include <bits/errno-return.h>
#include <fcntl.h>
2023-03-12 15:55:46 +00:00
#include <stdarg.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C"
{
2023-03-12 15:55:46 +00:00
int open(const char* path, int flags, ...)
{
2023-03-12 15:55:46 +00:00
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);
2023-03-12 15:55:46 +00:00
va_end(ap);
__errno_return(rc, int);
}
2023-03-19 18:21:36 +00:00
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);
}
2023-03-19 18:21:36 +00:00
int creat(const char* path, mode_t mode)
{
return openat(AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode);
2023-03-19 18:21:36 +00:00
}
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);
}
}