X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Ffopen.c;h=252f08241b3a313c057b3c6d8fc6baa1e8278c43;hb=11ddc314b57196519316103b02acffe10299dad3;hp=469de6f0b62a6bf9d494859f186797a8103aa74e;hpb=eb0e8fa0b1960cff4bd65ebefc798f70273b0bc9;p=musl diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index 469de6f0..252f0824 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(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;