2023-03-11 16:45:20 +00:00
|
|
|
#include <bits/errno-return.h>
|
|
|
|
#include <fcntl.h>
|
2023-03-12 15:55:46 +00:00
|
|
|
#include <stdarg.h>
|
2023-03-11 16:45:20 +00:00
|
|
|
#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-11 16:45:20 +00:00
|
|
|
{
|
2023-03-12 15:55:46 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, flags);
|
|
|
|
|
|
|
|
mode_t mode = (mode_t)va_arg(ap, int);
|
|
|
|
|
2023-04-15 18:26:15 +00:00
|
|
|
long rc = syscall(SYS_openat, AT_FDCWD, path, flags, mode);
|
2023-03-12 15:55:46 +00:00
|
|
|
|
|
|
|
va_end(ap);
|
2023-03-11 16:45:20 +00:00
|
|
|
__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);
|
|
|
|
}
|
2023-03-24 20:33:20 +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);
|
|
|
|
}
|
2023-03-11 16:45:20 +00:00
|
|
|
}
|