aboutsummaryrefslogtreecommitdiff
path: root/sys/base/bufio/refill.h
blob: 41e357e465232953db42efaf190b9dc5f4d4a952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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;
}