aboutsummaryrefslogtreecommitdiff
path: root/sys/libn/bufio.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-05-17 18:28:05 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-05-17 18:28:05 -0700
commit23ac1f4f98accc3bb84e81be264d8408be372028 (patch)
treed3876d6d5ce73c9f0669ec3f0c04c3a7524ec91e /sys/libn/bufio.c
parent9ec5bed6a7d715ffa69851569485a685dd69db2e (diff)
fix: bugs associated to map reallocating
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;
}