X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-buffer.c;h=d8094eb027e2c880c69da1f0fda4550362deaeeb;hb=5a78c3505ae7fa76a061e26676450049ec5946d5;hp=574874f0a11aa2545f29ad5716394324b688f3cd;hpb=5be3a95b1ab568578ab13609ebfb31aeb76c2a3e;p=libucw.git diff --git a/lib/fb-buffer.c b/lib/fb-buffer.c index 574874f0..d8094eb0 100644 --- a/lib/fb-buffer.c +++ b/lib/fb-buffer.c @@ -1,7 +1,7 @@ /* - * Sherlock Library -- Fast Buffered I/O on Static Buffers + * UCW Library -- Fast Buffered I/O on Static Buffers * - * (c) 2003--2004 Martin Mares + * (c) 2003--2006 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -10,12 +10,29 @@ #include "lib/lib.h" #include "lib/fastbuf.h" +#include +#include + static int fbbuf_refill(struct fastbuf *f UNUSED) { return 0; } +static int +fbbuf_seek(struct fastbuf *f, sh_off_t pos, int whence) +{ + /* 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, uns can_overwrite) { @@ -25,7 +42,7 @@ fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite) f->pos = size; f->refill = fbbuf_refill; f->spout = NULL; - f->seek = NULL; + f->seek = fbbuf_seek; f->close = NULL; f->config = NULL; f->can_overwrite_buffer = can_overwrite;