commit 9af5dd1c8a0f4ed051b7247ca759263f5cfee054
parent 1f27546ac6b0a4fd6f0c5198afa34d5220e57107
Author: sin <sin@2f30.org>
Date: Thu, 21 Feb 2019 14:57:30 +0000
Ensure chunker is refilled up to capacity
Previously we were not refilling the chunker up to its max capacity
when reading from a pipe.
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/chunker.c b/chunker.c
@@ -81,11 +81,16 @@ fill_chunker(struct chunker *chunker)
uint8_t *bp;
ssize_t n;
- bp = &chunker->buf[chunker->wpos];
- n = read(chunker->fd, bp, chunker->cap - chunker->wpos);
- if (n < 0)
- err(1, "read");
- chunker->wpos += n;
+ while (chunker->cap != chunker->wpos) {
+ bp = &chunker->buf[chunker->wpos];
+ n = read(chunker->fd, bp, chunker->cap - chunker->wpos);
+ if (n < 0)
+ err(1, "read");
+ else if (n == 0)
+ break;
+ chunker->wpos += n;
+ }
+
return chunker->wpos;
}