X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-mem.c;h=c304e16db0b988b73aaf630ecb0af0fe335fdebf;hb=1d8112cb590e458baa899805908a8ac910f58163;hp=2b0d7e941fa6cf1c9e0e408efe02a3a184bb67d8;hpb=43ad0ca991bb413356651deac398aea6a92eb52d;p=libucw.git diff --git a/lib/fb-mem.c b/lib/fb-mem.c index 2b0d7e94..c304e16d 100644 --- a/lib/fb-mem.c +++ b/lib/fb-mem.c @@ -1,5 +1,5 @@ /* - * Sherlock Library -- Fast Buffered I/O on Memory Streams + * UCW Library -- Fast Buffered I/O on Memory Streams * * (c) 1997--2002 Martin Mares * @@ -10,7 +10,7 @@ #include "lib/lib.h" #include "lib/fastbuf.h" -#include +#include struct memstream { unsigned blocksize; @@ -95,7 +95,7 @@ fbmem_spout(struct fastbuf *f) FB_MEM(f)->block = bb; } -static void +static int fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence) { struct memstream *m = FB_MEM(f)->stream; @@ -117,9 +117,17 @@ fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence) f->bufend = f->bstop = b->data + b->size; f->pos = b->pos + b->size; FB_MEM(f)->block = b; - return; + return 1; } } + if (!m->first && !pos) + { + /* Seeking to offset 0 in an empty file needs an exception */ + f->buffer = f->bptr = f->bufend = NULL; + f->pos = 0; + FB_MEM(f)->block = NULL; + return 1; + } die("fbmem_seek to invalid offset"); } @@ -171,6 +179,7 @@ fbmem_clone_read(struct fastbuf *b) f->refill = fbmem_refill; f->seek = fbmem_seek; f->close = fbmem_close; + f->can_overwrite_buffer = 1; return f; }