]> mj.ucw.cz Git - libucw.git/blob - lib/fb-buffer.c
BCONFIG_CAN_OVERWRITE is a read/write parameter, i.e. the used can
[libucw.git] / lib / fb-buffer.c
1 /*
2  *      Sherlock Library -- Fast Buffered I/O on Static Buffers
3  *
4  *      (c) 2003 Martin Mares <mj@ucw.cz>
5  *      (c) 2004 Robert Spalek <robert@ucw.cz>
6  *
7  *      This software may be freely distributed and used according to the terms
8  *      of the GNU Lesser General Public License.
9  */
10
11 #include "lib/lib.h"
12 #include "lib/fastbuf.h"
13
14 static int
15 fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED)
16 {
17   switch (item)
18     {
19     case BCONFIG_CAN_OVERWRITE:
20       // XXX: should we enable changing the value?
21       return 1;
22     default:
23       return -1;
24     }
25 }
26
27 static int
28 fbbuf_refill(struct fastbuf *f UNUSED)
29 {
30   return 0;
31 }
32
33 void
34 fbbuf_init_read(struct fastbuf *f, byte *buf, uns size)
35 {
36   f->buffer = f->bptr = buf;
37   f->bstop = f->bufend = buf + size;
38   f->name = "fbbuf-read";
39   f->pos = size;
40   f->refill = fbbuf_refill;
41   f->spout = NULL;
42   f->seek = NULL;
43   f->close = NULL;
44   f->config = fbbuf_config;
45 }
46
47 static void
48 fbbuf_spout(struct fastbuf *f UNUSED)
49 {
50   die("fbbuf: buffer overflow on write");
51 }
52
53 void
54 fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
55 {
56   f->buffer = f->bstop = f->bptr = buf;
57   f->bufend = buf + size;
58   f->name = "fbbuf-write";
59   f->pos = size;
60   f->refill = NULL;
61   f->spout = fbbuf_spout;
62   f->seek = NULL;
63   f->close = NULL;
64   f->config = fbbuf_config;
65 }