]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-mem.c
fixed bugs causing the imagesig analyser to fail in scanner
[libucw.git] / lib / fb-mem.c
index 2b0d7e941fa6cf1c9e0e408efe02a3a184bb67d8..0de590e04fb90b19cca2c567f2c7c338d75b4180 100644 (file)
@@ -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 <mj@ucw.cz>
  *
@@ -10,8 +10,6 @@
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 
-#include <stdlib.h>
-
 struct memstream {
   unsigned blocksize;
   unsigned uc;
@@ -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;
 }