]> mj.ucw.cz Git - libucw.git/commitdiff
Added very simple functions for emulating a fastbuf stream over a static
authorMartin Mares <mj@ucw.cz>
Sat, 22 Nov 2003 18:21:22 +0000 (18:21 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 22 Nov 2003 18:21:22 +0000 (18:21 +0000)
buffer. The struct fastbuf is allocated statically as well to make everything
as simple and as fast as possible.

lib/Makefile
lib/fastbuf.h
lib/fb-buffer.c [new file with mode: 0644]

index d31c66be2960957f9cefcb1187329c1a6b943316..7bb2c7c473ff5c61248f70bae9ef649bf0e9d6f8 100644 (file)
@@ -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 \
        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))
 LIBSH_MOD_PATHS=$(addprefix obj/lib/,$(LIBSH_MODS)) $(CUSTOM_LIB_MODULES)
 
 obj/lib/libsh.a: $(addsuffix .o,$(LIBSH_MOD_PATHS))
index 8699fe40ef4ceea1f4015d64215f0acdb85945d6..266ea220e2ae14ba8c4bb7cf252a08bac5228c02 100644 (file)
@@ -86,6 +86,16 @@ struct fastbuf *bopen_mm(byte *name, uns mode);
 
 struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit);
 
 
 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);
 /* 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 (file)
index 0000000..03c8e32
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ *     Sherlock Library -- Fast Buffered I/O on Static Buffers
+ *
+ *     (c) 2003 Martin Mares <mj@ucw.cz>
+ *
+ *     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;
+}