]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-mem.c
Opt: Calling hooks, config opts added
[libucw.git] / ucw / fb-mem.c
index a100d481f05016f720295ea1183499804f635e1c..71b171c7c994e21e1ba9ab7ad2110f8e7376dda9 100644 (file)
@@ -7,8 +7,8 @@
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
 
 #include <stdio.h>
 
@@ -30,7 +30,7 @@ struct fb_mem {
   struct memstream *stream;
   struct msblock *block;
 };
-#define FB_MEM(f) ((struct fb_mem *)(f)->is_fastbuf)
+#define FB_MEM(f) ((struct fb_mem *)(f))
 
 static int
 fbmem_refill(struct fastbuf *f)
@@ -112,10 +112,10 @@ fbmem_seek(struct fastbuf *f, ucw_off_t pos, int whence)
     {
       if (pos <= b->pos + (ucw_off_t)b->size) /* <=, because we need to be able to seek just after file end */
        {
-         f->buffer = b->data;
+         f->buffer = f->bstop = b->data;
          f->bptr = b->data + (pos - b->pos);
-         f->bufend = f->bstop = b->data + b->size;
-         f->pos = b->pos + b->size;
+         f->bufend = b->data + b->size;
+         f->pos = b->pos;
          FB_MEM(f)->block = b;
          return 1;
        }
@@ -123,12 +123,12 @@ fbmem_seek(struct fastbuf *f, ucw_off_t pos, int whence)
   if (!m->first && !pos)
     {
       /* Seeking to offset 0 in an empty file needs an exception */
-      f->buffer = f->bptr = f->bufend = NULL;
+      f->buffer = f->bptr = f->bstop = f->bufend = NULL;
       f->pos = 0;
       FB_MEM(f)->block = NULL;
       return 1;
     }
-  die("fbmem_seek to invalid offset");
+  bthrow(f, "seek", "fbmem_seek to an invalid offset");
 }
 
 static void
@@ -162,7 +162,6 @@ fbmem_create(unsigned blocksize)
   f->name = "<fbmem-write>";
   f->spout = fbmem_spout;
   f->close = fbmem_close;
-  fb_tie(f);
   return f;
 }
 
@@ -181,7 +180,6 @@ fbmem_clone_read(struct fastbuf *b)
   f->seek = fbmem_seek;
   f->close = fbmem_close;
   f->can_overwrite_buffer = 1;
-  fb_tie(f);
   return f;
 }