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 "ucw/fastbuf.h"
17 fbbuf_refill(struct fastbuf *f UNUSED)
23 fbbuf_seek(struct fastbuf *f, sh_off_t pos, int whence)
25 /* Somebody might want to seek to the end of buffer, try to be nice to him. */
26 sh_off_t len = f->bufend - f->buffer;
27 if (whence == SEEK_END)
29 ASSERT(pos >= 0 && pos <= len);
30 f->bptr = f->buffer + pos;
37 fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite)
39 f->buffer = f->bptr = buf;
40 f->bstop = f->bufend = buf + size;
41 f->name = "fbbuf-read";
43 f->refill = fbbuf_refill;
48 f->can_overwrite_buffer = can_overwrite;
52 fbbuf_spout(struct fastbuf *f UNUSED)
54 die("fbbuf: buffer overflow on write");
58 fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
60 f->buffer = f->bstop = f->bptr = buf;
61 f->bufend = buf + size;
62 f->name = "fbbuf-write";
65 f->spout = fbbuf_spout;
69 f->can_overwrite_buffer = 0;