aboutsummaryrefslogtreecommitdiff
path: root/sys/libn
diff options
context:
space:
mode:
Diffstat (limited to 'sys/libn')
-rw-r--r--sys/libn/bufio.c15
-rw-r--r--sys/libn/io.c2
2 files changed, 6 insertions, 11 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;
}
diff --git a/sys/libn/io.c b/sys/libn/io.c
index 2852f42..08c29b0 100644
--- a/sys/libn/io.c
+++ b/sys/libn/io.c
@@ -25,7 +25,7 @@ io·stat(Stream *s, io·Stat *buf)
int
io·exists(byte *path, int flag)
{
- return access(path, flag);
+ return access(path, flag) == 0;
}
error