2 * UCW Library -- Null fastbuf
4 * (c) 2014 Pavel Charvat <pchar@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/fastbuf.h>
15 static void fbnull_close(struct fastbuf *b)
20 struct fastbuf *fbnull_open(uns bufsize)
22 struct fastbuf *b = xmalloc(sizeof(*b) + bufsize);
25 b->close = fbnull_close;
26 fbnull_start(b, (byte *)(b + 1), bufsize);
30 static int fbnull_refill(struct fastbuf *b UNUSED)
35 static void fbnull_spout(struct fastbuf *b)
37 b->pos += b->bptr - b->bstop;
41 static int fbnull_seek(struct fastbuf *b, ucw_off_t pos, int whence)
43 b->pos = (whence == SEEK_END) ? 0 : pos;
48 void fbnull_start(struct fastbuf *b, byte *buf, uns bufsize)
50 ASSERT(buf && bufsize);
52 b->buffer = b->bptr = b->bstop = buf;
53 b->bufend = buf + bufsize;
54 b->refill = fbnull_refill;
55 b->spout = fbnull_spout;
56 b->seek = fbnull_seek;
57 b->can_overwrite_buffer = 2;
60 bool fbnull_test(struct fastbuf *b)
62 return b->refill == fbnull_refill;
68 struct fastbuf *b = fbnull_open(7);
69 for (uns i = 0; i < 100; i++)
71 if (btell(b) != i * 10)
75 bputs(b, "0123456789");
78 if (bfilesize(b) != 0)
80 if (btell(b) != 100 * 10)