diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
commit | ce05175372a9ddca1a225db0765ace1127a39293 (patch) | |
tree | 5988b4d4f6b402e4953945886fc90aae11203df6 /src/base/bufio/refill.h | |
parent | b375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff) |
chore: simplified organizational structurelaptop
Diffstat (limited to 'src/base/bufio/refill.h')
-rw-r--r-- | src/base/bufio/refill.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/base/bufio/refill.h b/src/base/bufio/refill.h new file mode 100644 index 0000000..41e357e --- /dev/null +++ b/src/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; +} |