summaryrefslogtreecommitdiff
path: root/src/stdio/__stdio_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/__stdio_read.c')
-rw-r--r--src/stdio/__stdio_read.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c
index d9bb3269..a2e4cd62 100644
--- a/src/stdio/__stdio_read.c
+++ b/src/stdio/__stdio_read.c
@@ -2,5 +2,21 @@
size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
{
- return syscall(SYS_read, f->fd, buf, len);
+ struct iovec iov[2] = {
+ { .iov_base = buf, .iov_len = len },
+ { .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 <= len) return cnt;
+ cnt -= len;
+ f->rpos = f->buf;
+ f->rend = f->buf + cnt;
+ return len;
}