X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-mem.c;h=0de590e04fb90b19cca2c567f2c7c338d75b4180;hb=e4c695d49529d03352d241872493a5161e646288;hp=0f3158c379dbc9e7ae666c35d90e0d91c6bdfb32;hpb=cf83e06e4158617e981fef5bf3878315b23bf7f9;p=libucw.git diff --git a/lib/fb-mem.c b/lib/fb-mem.c index 0f3158c3..0de590e0 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,8 +10,6 @@ #include "lib/lib.h" #include "lib/fastbuf.h" -#include - struct memstream { unsigned blocksize; unsigned uc; @@ -110,7 +108,7 @@ fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence) /* Yes, this is linear. But considering the average number of buckets, it doesn't matter. */ for (b=m->first; b; b=b->next) { - if (pos <= b->pos + b->size) /* <=, because we need to be able to seek just after file end */ + if (pos <= b->pos + (sh_off_t)b->size) /* <=, because we need to be able to seek just after file end */ { f->buffer = b->data; f->bptr = b->data + (pos - b->pos); @@ -120,6 +118,14 @@ fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence) return; } } + 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; + } die("fbmem_seek to invalid offset"); } @@ -171,6 +177,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; }