]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/fb-mem.c
tableprinter: code cleanup
[libucw.git] / ucw / fb-mem.c
index 1acb38f6c3f6721b6742abe67934cbe8ce70a7f0..77ad43d94f09573bd53d721aee8ff969db6c7c8c 100644 (file)
@@ -7,21 +7,21 @@
  *     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>
 
 struct memstream {
-  unsigned blocksize;
-  unsigned uc;
+  uint blocksize;
+  uint uc;
   struct msblock *first;
 };
 
 struct msblock {
   struct msblock *next;
   ucw_off_t pos;
-  unsigned size;
+  uint size;
   byte data[0];
 };
 
@@ -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
@@ -150,7 +150,7 @@ fbmem_close(struct fastbuf *f)
 }
 
 struct fastbuf *
-fbmem_create(unsigned blocksize)
+fbmem_create(uint blocksize)
 {
   struct fastbuf *f = xmalloc_zero(sizeof(struct fb_mem));
   struct memstream *s = xmalloc_zero(sizeof(struct memstream));