]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-mem.c
Added string functions for matching of prefixes and suffixes
[libucw.git] / ucw / fb-mem.c
index 40b9f1e5458034594b18ff1901b3df0c2bf64f23..bacdf03ff10260d7eb83ff2527297d18bb89f60d 100644 (file)
@@ -20,7 +20,7 @@ struct memstream {
 
 struct msblock {
   struct msblock *next;
-  sh_off_t pos;
+  ucw_off_t pos;
   unsigned size;
   byte data[0];
 };
@@ -96,7 +96,7 @@ fbmem_spout(struct fastbuf *f)
 }
 
 static int
-fbmem_seek(struct fastbuf *f, sh_off_t pos, int whence)
+fbmem_seek(struct fastbuf *f, ucw_off_t pos, int whence)
 {
   struct memstream *m = FB_MEM(f)->stream;
   struct msblock *b;
@@ -110,12 +110,12 @@ 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 + (sh_off_t)b->size) /* <=, because we need to be able to seek just after file end */
+      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, sh_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, "fb.seek", "fbmem_seek to invalid offset");
 }
 
 static void
@@ -162,7 +162,7 @@ fbmem_create(unsigned blocksize)
   f->name = "<fbmem-write>";
   f->spout = fbmem_spout;
   f->close = fbmem_close;
-  return f;
+  return fb_tie(f);
 }
 
 struct fastbuf *
@@ -180,7 +180,7 @@ fbmem_clone_read(struct fastbuf *b)
   f->seek = fbmem_seek;
   f->close = fbmem_close;
   f->can_overwrite_buffer = 1;
-  return f;
+  return fb_tie(f);
 }
 
 #ifdef TEST
@@ -213,6 +213,7 @@ int main(void)
   printf("<!%d>", (int)btell(r));
   while ((t = bgetc(r)) >= 0)
     putchar(t);
+  putchar('\n');
   fflush(stdout);
   bclose(r);
   return 0;