X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffopen.c;h=252f08241b3a313c057b3c6d8fc6baa1e8278c43;hb=6d99ad91e869aab35a4d76d34c3c9eaf29482bad;hp=03c10cd16c9a3436906b3d25356395719d118e3a;hpb=8582a6e9f25dd7b87d72961f58008052a4cac473;p=musl diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 03c10cd1..252f0824 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,4 +1,7 @@ #include "stdio_impl.h" +#include +#include +#include FILE *fopen(const char *restrict filename, const char *restrict mode) { @@ -13,17 +16,12 @@ FILE *fopen(const char *restrict filename, const char *restrict mode) } /* Compute the flags to pass to open() */ - if (strchr(mode, '+')) flags = O_RDWR; - else if (*mode == 'r') flags = O_RDONLY; - else flags = O_WRONLY; - if (strchr(mode, 'x')) flags |= O_EXCL; - if (strchr(mode, 'e')) flags |= O_CLOEXEC; - if (*mode != 'r') flags |= O_CREAT; - if (*mode == 'w') flags |= O_TRUNC; - if (*mode == 'a') flags |= O_APPEND; + flags = __fmodeflags(mode); - fd = syscall_cp(SYS_open, filename, flags|O_LARGEFILE, 0666); + fd = sys_open(filename, flags, 0666); if (fd < 0) return 0; + if (flags & O_CLOEXEC) + __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); f = __fdopen(fd, mode); if (f) return f;