| 3272 | } |
| 3273 | |
| 3274 | static FILE *fopen(const char *path, const char *mode) |
| 3275 | { |
| 3276 | int flags = stdio_parse_mode(mode); |
| 3277 | if (flags < 0) |
| 3278 | { |
| 3279 | errno = EINVAL; |
| 3280 | return NULL; |
| 3281 | } |
| 3282 | int fd = open(path, flags, |
| 3283 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); |
| 3284 | if (fd < 0) |
| 3285 | return NULL; |
| 3286 | bool r = ((flags & O_ACCMODE) != O_WRONLY? true: false); |
| 3287 | bool w = ((flags & O_ACCMODE) != O_RDONLY? true: false); |
| 3288 | FILE *stream = stdio_stream_alloc(fd, r, w, _IOFBF); |
| 3289 | if (stream == NULL) |
| 3290 | { |
| 3291 | close(fd); |
| 3292 | return NULL; |
| 3293 | } |
| 3294 | return stream; |
| 3295 | } |
| 3296 | |
| 3297 | static int fclose(FILE *stream) |
| 3298 | { |