1 #include "stdio_impl.h"
3 FILE *fopen(const char *filename, const char *mode)
8 int plus = !!strchr(mode, '+');
10 /* Check for valid initial mode character */
11 if (!strchr("rwa", *mode)) {
16 /* Compute the flags to pass to open() */
17 if (plus) flags = O_RDWR;
18 else if (*mode == 'r') flags = O_RDONLY;
19 else flags = O_WRONLY;
20 if (*mode != 'r') flags |= O_CREAT;
21 if (*mode == 'w') flags |= O_TRUNC;
22 if (*mode == 'a') flags |= O_APPEND;
24 fd = __syscall_open(filename, flags, 0666);
27 f = __fdopen(fd, mode);