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);
24 b->close = fbnull_close;
25 fbnull_start(b, (byte *)(b + 1), bufsize);
29 static int fbnull_refill(struct fastbuf *b UNUSED)
34 static void fbnull_spout(struct fastbuf *b)
36 b->pos += b->bptr - b->bstop;
40 static int fbnull_seek(struct fastbuf *b, ucw_off_t pos, int whence)
42 b->pos = (whence == SEEK_END) ? 0 : pos;
47 void fbnull_start(struct fastbuf *b, byte *buf, uns bufsize)
49 ASSERT(buf && bufsize);
51 b->buffer = b->bptr = b->bstop = buf;
52 b->bufend = buf + bufsize;
53 b->refill = fbnull_refill;
54 b->spout = fbnull_spout;
55 b->seek = fbnull_seek;
56 b->can_overwrite_buffer = 2;
59 bool fbnull_test(struct fastbuf *b)
61 return b->refill == fbnull_refill;
67 struct fastbuf *b = fbnull_open(7);
68 for (uns i = 0; i < 100; i++)
70 if (btell(b) != i * 10)
74 bputs(b, "0123456789");
77 if (bfilesize(b) != 0)
79 if (btell(b) != 100 * 10)