X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2F__stdio_read.c;h=05e56f923a8aef884a9a36bec983df605afabe32;hb=b5a527f9ff47b0f4b32c606e385a0c27d861a475;hp=218bd88d18df42d908dc121600af2cf242cb9abd;hpb=2cff36a84f268c09f4c9dc5a1340652c8e298dc0;p=musl diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index 218bd88d..05e56f92 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -1,4 +1,12 @@ #include "stdio_impl.h" +#include +#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 +16,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;