X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2F__stdio_read.c;h=218bd88d18df42d908dc121600af2cf242cb9abd;hb=cc44d9f2017855ad29c5c1301e8368158a4c2fa7;hp=ee7e12587ee667ce753206517d00c749b122bee2;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index ee7e1258..218bd88d 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -2,5 +2,22 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) { - return __syscall_read(f->fd, buf, len); + struct iovec iov[2] = { + { .iov_base = buf, .iov_len = len - !!f->buf_size }, + { .iov_base = f->buf, .iov_len = f->buf_size } + }; + ssize_t cnt; + + 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; + return cnt; + } + if (cnt <= iov[0].iov_len) return cnt; + cnt -= iov[0].iov_len; + f->rpos = f->buf; + f->rend = f->buf + cnt; + if (f->buf_size) buf[len-1] = *f->rpos++; + return len; }