X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2F__stdio_read.c;h=c99ca9a913314bdb15c221943327a39e50dc2a75;hb=d62f4e98881702f07501b965e5beebd7516deca2;hp=218bd88d18df42d908dc121600af2cf242cb9abd;hpb=2cff36a84f268c09f4c9dc5a1340652c8e298dc0;p=musl diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index 218bd88d..c99ca9a9 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -1,4 +1,11 @@ #include "stdio_impl.h" +#include + +static void cleanup(void *p) +{ + FILE *f = p; + if (!f->lockcount) __unlockfile(f); +} size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) { @@ -8,7 +15,13 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) }; ssize_t cnt; - cnt = syscall(SYS_readv, f->fd, iov, 2); + if (libc.main_thread) { + pthread_cleanup_push(cleanup, f); + cnt = syscall_cp(SYS_readv, f->fd, iov, 2); + pthread_cleanup_pop(0); + } else { + cnt = syscall(SYS_readv, f->fd, iov, 2); + } if (cnt <= 0) { f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); f->rpos = f->rend = 0;