X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffopen.c;h=e1b91e12d826357fd5058b913ba75b386be8a606;hb=59b64ff686cef2a87e9552658b2c8d2531f87176;hp=084cc73ce5ab7014821c3774f120c2fbd07d60c3;hpb=58165923890865a6ac042fafce13f440ee986fd9;p=musl diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 084cc73c..e1b91e12 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,15 +16,12 @@ 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); + 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; @@ -31,4 +30,4 @@ FILE *fopen(const char *filename, const char *mode) return 0; } -LFS64(fopen); +weak_alias(fopen, fopen64);