From: Martin Mares Date: Sat, 22 Nov 2003 18:21:22 +0000 (+0000) Subject: Added very simple functions for emulating a fastbuf stream over a static X-Git-Tag: holmes-import~1161 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;ds=sidebyside;h=f5be42dd4a3346059819fdba379e7abac9549625;p=libucw.git Added very simple functions for emulating a fastbuf stream over a static buffer. The struct fastbuf is allocated statically as well to make everything as simple and as fast as possible. --- diff --git a/lib/Makefile b/lib/Makefile index d31c66be..7bb2c7c4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -9,7 +9,7 @@ LIBSH_MODS=alloc alloc_str ctmatch db fastbuf fb-file fb-mem lists \ wordsplit str_ctype str_upper bucket conf object sorter \ finger proctitle ipaccess profile bitsig randomkey \ hashfunc base64 base224 fb-temp fb-mmap fb-printf urlkey \ - partmap fb-limfd + partmap fb-limfd fb-buffer LIBSH_MOD_PATHS=$(addprefix obj/lib/,$(LIBSH_MODS)) $(CUSTOM_LIB_MODULES) obj/lib/libsh.a: $(addsuffix .o,$(LIBSH_MOD_PATHS)) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 8699fe40..266ea220 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -86,6 +86,16 @@ struct fastbuf *bopen_mm(byte *name, uns mode); struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit); +/* FastIO on static buffers */ + +void fbbuf_init_read(struct fastbuf *f, byte *buffer, uns size); +void fbbuf_init_write(struct fastbuf *f, byte *buffer, uns size); +static inline uns +fbbuf_count_written(struct fastbuf *f) +{ + return f->bptr - f->bstop; +} + /* Configuring stream parameters */ int bconfig(struct fastbuf *f, uns type, int data); diff --git a/lib/fb-buffer.c b/lib/fb-buffer.c new file mode 100644 index 00000000..03c8e321 --- /dev/null +++ b/lib/fb-buffer.c @@ -0,0 +1,51 @@ +/* + * Sherlock Library -- Fast Buffered I/O on Static Buffers + * + * (c) 2003 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#include "lib/lib.h" +#include "lib/fastbuf.h" + +static int +fbbuf_refill(struct fastbuf *f UNUSED) +{ + return 0; +} + +void +fbbuf_init_read(struct fastbuf *f, byte *buf, uns size) +{ + f->buffer = f->bptr = buf; + f->bstop = f->bufend = buf + size; + f->name = "fbbuf-read"; + f->pos = size; + f->refill = fbbuf_refill; + f->spout = NULL; + f->seek = NULL; + f->close = NULL; + f->config = NULL; +} + +static void +fbbuf_spout(struct fastbuf *f UNUSED) +{ + die("fbbuf: buffer overflow on write"); +} + +void +fbbuf_init_write(struct fastbuf *f, byte *buf, uns size) +{ + f->buffer = f->bstop = f->bptr = buf; + f->bufend = buf + size; + f->name = "fbbuf-write"; + f->pos = size; + f->refill = NULL; + f->spout = fbbuf_spout; + f->seek = NULL; + f->close = NULL; + f->config = NULL; +}