Luna/libc/src/fcntl.cpp

40 lines
781 B
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_open, 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 open(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);
}
}