X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffopen.c;h=da17ce8b48dc431d6aa70539bbb136841e8f727d;hb=b5a527f9ff47b0f4b32c606e385a0c27d861a475;hp=084cc73ce5ab7014821c3774f120c2fbd07d60c3;hpb=58165923890865a6ac042fafce13f440ee986fd9;p=musl diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 084cc73c..da17ce8b 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,11 +1,13 @@ #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; int flags; - int plus = !!strchr(mode, '+'); /* Check for valid initial mode character */ if (!strchr("rwa", *mode)) { @@ -14,12 +16,7 @@ FILE *fopen(const char *filename, const char *mode) } /* Compute the flags to pass to open() */ - if (plus) flags = O_RDWR; - else if (*mode == 'r') flags = O_RDONLY; - else flags = O_WRONLY; - 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;