From 46e1370545220ca877645e2a7e2ab95e5accc505 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 17 Mar 2006 22:27:40 +0100 Subject: [PATCH] Support seeks on fbbuf streams. --- lib/fb-buffer.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/fb-buffer.c b/lib/fb-buffer.c index b06088e0..09c74293 100644 --- a/lib/fb-buffer.c +++ b/lib/fb-buffer.c @@ -1,7 +1,7 @@ /* * 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,27 @@ #include "lib/lib.h" #include "lib/fastbuf.h" +#include + static int fbbuf_refill(struct fastbuf *f UNUSED) { return 0; } +static void +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; +} + void fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite) { @@ -25,7 +40,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; -- 2.39.2