1 #include "stdio_impl.h"
3 FILE *fopen(const char *restrict filename, const char *restrict mode)
9 /* Check for valid initial mode character */
10 if (!strchr("rwa", *mode)) {
15 /* Compute the flags to pass to open() */
16 if (strchr(mode, '+')) flags = O_RDWR;
17 else if (*mode == 'r') flags = O_RDONLY;
18 else flags = O_WRONLY;
19 if (strchr(mode, 'x')) flags |= O_EXCL;
20 if (strchr(mode, 'e')) flags |= O_CLOEXEC;
21 if (*mode != 'r') flags |= O_CREAT;
22 if (*mode == 'w') flags |= O_TRUNC;
23 if (*mode == 'a') flags |= O_APPEND;
25 fd = syscall_cp(SYS_open, filename, flags|O_LARGEFILE, 0666);
28 f = __fdopen(fd, mode);
31 __syscall(SYS_close, fd);