]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.c
written parsing config files and command line parameters, untested yet
[libucw.git] / lib / fastbuf.c
index 717372fdfcfb42f797b1d2199d96d87f86467216..1a1457844a1f9b46fb8b037972ee6b27c52a24d6 100644 (file)
@@ -4,17 +4,17 @@
  *     (c) 1997--2000 Martin Mares <mj@ucw.cz>
  */
 
+#include "lib/lib.h"
+#include "lib/fastbuf.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "lib.h"
-#include "fastbuf.h"
-
 void bclose(struct fastbuf *f)
 {
   bflush(f);
   f->close(f);
-  free(f);
+  xfree(f);
 }
 
 void bflush(struct fastbuf *f)
@@ -44,8 +44,6 @@ inline void bsetpos(struct fastbuf *f, sh_off_t pos)
 
 void bseek(struct fastbuf *f, sh_off_t pos, int whence)
 {
-  sh_off_t l;
-
   switch (whence)
     {
     case SEEK_SET:
@@ -186,8 +184,9 @@ void bput5_slow(struct fastbuf *f, u64 o)
 #endif
 }
 
-void bread_slow(struct fastbuf *f, void *b, uns l)
+uns bread_slow(struct fastbuf *f, void *b, uns l)
 {
+  uns total = 0;
   while (l)
     {
       uns k = f->bstop - f->bptr;
@@ -197,7 +196,7 @@ void bread_slow(struct fastbuf *f, void *b, uns l)
          f->refill(f);
          k = f->bstop - f->bptr;
          if (!k)
-           die("bread on %s: file exhausted", f->name);
+           break;
        }
       if (k > l)
        k = l;
@@ -205,7 +204,9 @@ void bread_slow(struct fastbuf *f, void *b, uns l)
       f->bptr += k;
       b = (byte *)b + k;
       l -= k;
+      total += k;
     }
+  return total;
 }
 
 void bwrite_slow(struct fastbuf *f, void *b, uns l)