X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffopen.c;h=da17ce8b48dc431d6aa70539bbb136841e8f727d;hb=4ca442157e381690202c3bcc102627d137fd0466;hp=0d5b1af25c81f74ffe7b19e2d1dab5d2d6cb3717;hpb=9bff7c133e73ecfb200614d7a7d386a164a1a61f;p=musl diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 0d5b1af2..da17ce8b 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,6 +1,9 @@ #include "stdio_impl.h" +#include +#include +#include -FILE *fopen(const char *filename, const char *mode) +FILE *fopen(const char *restrict filename, const char *restrict mode) { FILE *f; int fd; @@ -13,13 +16,7 @@ FILE *fopen(const char *filename, const char *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 (*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); if (fd < 0) return 0;