about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/stdio/__stdio_read.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c
index a2e4cd62..218bd88d 100644
--- a/src/stdio/__stdio_read.c
+++ b/src/stdio/__stdio_read.c
@@ -3,7 +3,7 @@
 size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
 {
 	struct iovec iov[2] = {
-		{ .iov_base = buf, .iov_len = len },
+		{ .iov_base = buf, .iov_len = len - !!f->buf_size },
 		{ .iov_base = f->buf, .iov_len = f->buf_size }
 	};
 	ssize_t cnt;
@@ -14,9 +14,10 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
 		f->rpos = f->rend = 0;
 		return cnt;
 	}
-	if (cnt <= len) return cnt;
-	cnt -= len;
+	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;
 }