OLD | NEW |
1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
2 #include <fcntl.h> | 2 #include <fcntl.h> |
3 #include <string.h> | 3 #include <string.h> |
4 #include <errno.h> | 4 #include <errno.h> |
5 | 5 |
6 FILE *fopen(const char *restrict filename, const char *restrict mode) | 6 FILE* fopen(const char* restrict filename, const char* restrict mode) { |
7 { | 7 FILE* f; |
8 » FILE *f; | 8 int fd; |
9 » int fd; | 9 int flags; |
10 » int flags; | |
11 | 10 |
12 » /* Check for valid initial mode character */ | 11 /* Check for valid initial mode character */ |
13 » if (!strchr("rwa", *mode)) { | 12 if (!strchr("rwa", *mode)) { |
14 » » errno = EINVAL; | 13 errno = EINVAL; |
15 » » return 0; | 14 return 0; |
16 » } | 15 } |
17 | 16 |
18 » /* Compute the flags to pass to open() */ | 17 /* Compute the flags to pass to open() */ |
19 » flags = __fmodeflags(mode); | 18 flags = __fmodeflags(mode); |
20 | 19 |
21 » fd = sys_open(filename, flags, 0666); | 20 fd = sys_open(filename, flags, 0666); |
22 » if (fd < 0) return 0; | 21 if (fd < 0) |
23 » if (flags & O_CLOEXEC) | 22 return 0; |
24 » » __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); | 23 if (flags & O_CLOEXEC) |
| 24 __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); |
25 | 25 |
26 » f = __fdopen(fd, mode); | 26 f = __fdopen(fd, mode); |
27 » if (f) return f; | 27 if (f) |
| 28 return f; |
28 | 29 |
29 » __syscall(SYS_close, fd); | 30 __syscall(SYS_close, fd); |
30 » return 0; | 31 return 0; |
31 } | 32 } |
32 | 33 |
33 LFS64(fopen); | 34 LFS64(fopen); |
OLD | NEW |