2 * UCW Library -- Fast Buffered I/O on Static Buffers
4 * (c) 2003--2006 Martin Mares <mj@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 "lib/fastbuf.h"
16 fbbuf_refill(struct fastbuf *f UNUSED)
22 fbbuf_seek(struct fastbuf *f, sh_off_t pos, int whence)
24 /* Somebody might want to seek to the end of buffer, try to be nice to him. */
25 sh_off_t len = f->bufend - f->buffer;
26 if (whence == SEEK_END)
28 ASSERT(pos >= 0 && pos <= len);
29 f->bptr = f->buffer + pos;
35 fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite)
37 f->buffer = f->bptr = buf;
38 f->bstop = f->bufend = buf + size;
39 f->name = "fbbuf-read";
41 f->refill = fbbuf_refill;
46 f->can_overwrite_buffer = can_overwrite;
50 fbbuf_spout(struct fastbuf *f UNUSED)
52 die("fbbuf: buffer overflow on write");
56 fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
58 f->buffer = f->bstop = f->bptr = buf;
59 f->bufend = buf + size;
60 f->name = "fbbuf-write";
63 f->spout = fbbuf_spout;
67 f->can_overwrite_buffer = 0;