aboutsummaryrefslogtreecommitdiff
path: root/sys/libn/bufio.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/libn/bufio.c')
-rw-r--r--sys/libn/bufio.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/sys/libn/bufio.c b/sys/libn/bufio.c
index ac8e175..05b6068 100644
--- a/sys/libn/bufio.c
+++ b/sys/libn/bufio.c
@@ -18,7 +18,7 @@ bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h)
buf->beg = buf->buf + bufio·ungets;
buf->pos = buf->beg;
buf->end = buf->pos;
- buf->size = buf->end - buf->beg;
+ buf->size = bufio·size - bufio·ungets;
return 0;
}
@@ -40,8 +40,9 @@ refill(io·Buffer *buf)
if (buf->state & bufio·end) {
return bufio·err;
}
+ memcpy(buf->buf, buf->pos - bufio·ungets, bufio·ungets);
- n = buf->rdr.read(buf->h, 1, buf->size, buf->buf);
+ n = buf->rdr.read(buf->h, 1, buf->size, buf->beg);
if (n < 0)
return bufio·err;
if (n == 0) {
@@ -49,14 +50,8 @@ refill(io·Buffer *buf)
return 0;
}
- if (n < buf->size) {
- d = buf->size - n;
-
- buf->state |= bufio·end;
-
- memmove(buf->pos + d, buf->pos, n);
- memmove(buf->pos + d - bufio·ungets, buf->buf, bufio·ungets);
- }
+ buf->pos = buf->beg;
+ buf->end = buf->pos + n;
return n;
}