From 9695ea005d4af93dcd60f74f10fd3c54499a182f Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Thu, 11 Nov 2021 16:31:58 -0800 Subject: chore: split up base library into individual files for smaller binaries --- sys/base/bufio/refill.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sys/base/bufio/refill.h (limited to 'sys/base/bufio/refill.h') diff --git a/sys/base/bufio/refill.h b/sys/base/bufio/refill.h new file mode 100644 index 0000000..41e357e --- /dev/null +++ b/sys/base/bufio/refill.h @@ -0,0 +1,28 @@ +int +refill(io·Buffer *buf) +{ + int n; + + 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->beg); + if(n < 0) + return bufio·err; + if(n == 0){ + buf->state |= bufio·end; + return 0; + } + + buf->pos = buf->beg; + buf->end = buf->pos + n; + + // TEST: put a physical EOF byte at the end + // this would allow for an unget operation + if(n < buf->size) + *buf->end++ = EOF; + + return n; +} -- cgit v1.2.1