X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-buffer.c;h=d8094eb027e2c880c69da1f0fda4550362deaeeb;hb=ba9c448bb5446d0100173e7a594bcb1d849b4e39;hp=2f52665f1bfbb879d69b9adaec550499b99a09e7;hpb=61da975c346c50ccf9bb9cb7271ef538dc15ab32;p=libucw.git diff --git a/lib/fb-buffer.c b/lib/fb-buffer.c index 2f52665f..d8094eb0 100644 --- a/lib/fb-buffer.c +++ b/lib/fb-buffer.c @@ -1,8 +1,7 @@ /* - * Sherlock Library -- Fast Buffered I/O on Static Buffers + * UCW Library -- Fast Buffered I/O on Static Buffers * - * (c) 2003 Martin Mares - * (c) 2004 Robert Spalek + * (c) 2003--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -11,27 +10,31 @@ #include "lib/lib.h" #include "lib/fastbuf.h" +#include +#include + static int -fbbuf_config(struct fastbuf *f UNUSED, uns item, int value UNUSED) +fbbuf_refill(struct fastbuf *f UNUSED) { - switch (item) - { - case BCONFIG_CAN_OVERWRITE: - // XXX: should we enable changing the value? - return 1; - default: - return -1; - } + return 0; } static int -fbbuf_refill(struct fastbuf *f UNUSED) +fbbuf_seek(struct fastbuf *f, sh_off_t pos, int whence) { - return 0; + /* Somebody might want to seek to the end of buffer, try to be nice to him. */ + sh_off_t len = f->bufend - f->buffer; + if (whence == SEEK_END) + pos += len; + ASSERT(pos >= 0 && pos <= len); + f->bptr = f->buffer + pos; + f->bstop = f->bufend; + f->pos = len; + return 1; } void -fbbuf_init_read(struct fastbuf *f, byte *buf, uns size) +fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite) { f->buffer = f->bptr = buf; f->bstop = f->bufend = buf + size; @@ -39,9 +42,10 @@ fbbuf_init_read(struct fastbuf *f, byte *buf, uns size) f->pos = size; f->refill = fbbuf_refill; f->spout = NULL; - f->seek = NULL; + f->seek = fbbuf_seek; f->close = NULL; - f->config = fbbuf_config; + f->config = NULL; + f->can_overwrite_buffer = can_overwrite; } static void @@ -61,5 +65,6 @@ fbbuf_init_write(struct fastbuf *f, byte *buf, uns size) f->spout = fbbuf_spout; f->seek = NULL; f->close = NULL; - f->config = fbbuf_config; + f->config = NULL; + f->can_overwrite_buffer = 0; }