2018-05-02 06:20:06 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <va_list.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <syscall.h>
|
2018-12-10 04:09:27 +03:00
|
|
|
#include <syscall_nums.h>
|
2018-05-02 06:20:06 +03:00
|
|
|
|
2018-12-10 04:09:27 +03:00
|
|
|
DEFN_SYSCALL3(open, SYS_OPEN, const char *, int, int);
|
2018-05-02 06:20:06 +03:00
|
|
|
|
|
|
|
int open(const char *name, int flags, ...) {
|
|
|
|
va_list argp;
|
|
|
|
int mode = 0;
|
|
|
|
int result;
|
|
|
|
va_start(argp, flags);
|
|
|
|
if (flags & O_CREAT) mode = va_arg(argp, int);
|
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
result = syscall_open(name, flags, mode);
|
|
|
|
if (result == -1) {
|
2018-07-18 04:45:42 +03:00
|
|
|
/* Not sure this is necessary */
|
2018-05-02 06:20:06 +03:00
|
|
|
if (flags & O_CREAT) {
|
|
|
|
errno = EACCES;
|
|
|
|
} else {
|
|
|
|
errno = ENOENT;
|
|
|
|
}
|
|
|
|
} else if (result < 0) {
|
|
|
|
errno = -result;
|
2018-07-18 04:45:42 +03:00
|
|
|
result = -1;
|
2018-05-02 06:20:06 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|