]> mj.ucw.cz Git - libucw.git/commitdiff
bread() now returns the number of bytes read instead of dying when
authorMartin Mares <mj@ucw.cz>
Sun, 7 Jan 2001 14:58:11 +0000 (14:58 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 7 Jan 2001 14:58:11 +0000 (14:58 +0000)
the file is too short.

Need to be taken care of when porting old Sherlock code.

lib/fastbuf.c
lib/fastbuf.h

index 0939b6d512533ad5bb9979b45eb3193a2b6879f8..1a1457844a1f9b46fb8b037972ee6b27c52a24d6 100644 (file)
@@ -184,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;
@@ -195,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;
@@ -203,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)
index c62ed4cd470cf2af754ce50b46ee398cfbffb2a3..e215b3ca6c455f54d10aba593e57fa625e9bb76f 100644 (file)
@@ -264,16 +264,17 @@ static inline void bput5(struct fastbuf *f, u64 l)
     bput5_slow(f, l);
 }
 
-void bread_slow(struct fastbuf *f, void *b, uns l);
-static inline void bread(struct fastbuf *f, void *b, uns l)
+uns bread_slow(struct fastbuf *f, void *b, uns l);
+static inline uns bread(struct fastbuf *f, void *b, uns l)
 {
   if (f->bptr + l <= f->bstop)
     {
       memcpy(b, f->bptr, l);
       f->bptr += l;
+      return l;
     }
   else
-    bread_slow(f, b, l);
+    return bread_slow(f, b, l);
 }
 
 void bwrite_slow(struct fastbuf *f, void *b, uns l);