]> mj.ucw.cz Git - libucw.git/commitdiff
Added breadb() which acts just like bread(), but die()s if a partial
authorMartin Mares <mj@ucw.cz>
Mon, 19 Feb 2001 18:53:46 +0000 (18:53 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 19 Feb 2001 18:53:46 +0000 (18:53 +0000)
record is read. This is mainly to avoid consistency checks in main
code path.

lib/fastbuf.c
lib/fastbuf.h

index 5b394cf1c867c2f755b07db788a562ad3e3fb84c..e9de62df425c9f1cf20c437eafa29205c8c1bfcb 100644 (file)
@@ -187,7 +187,7 @@ void bput5_slow(struct fastbuf *f, u64 o)
 #endif
 }
 
-uns bread_slow(struct fastbuf *f, void *b, uns l)
+uns bread_slow(struct fastbuf *f, void *b, uns l, uns check)
 {
   uns total = 0;
   while (l)
@@ -209,6 +209,8 @@ uns bread_slow(struct fastbuf *f, void *b, uns l)
       l -= k;
       total += k;
     }
+  if (check && total && total != l)
+    die("breadb: short read");
   return total;
 }
 
index 01e7f60a28f05a154c3c7996b08f164c9a4013d4..15bfed5a89cf1b42541c3dcdc5a7a12717feeab4 100644 (file)
@@ -268,7 +268,7 @@ static inline void bput5(struct fastbuf *f, u64 l)
     bput5_slow(f, l);
 }
 
-uns bread_slow(struct fastbuf *f, void *b, uns l);
+uns bread_slow(struct fastbuf *f, void *b, uns l, uns check);
 static inline uns bread(struct fastbuf *f, void *b, uns l)
 {
   if (f->bptr + l <= f->bstop)
@@ -278,7 +278,19 @@ static inline uns bread(struct fastbuf *f, void *b, uns l)
       return l;
     }
   else
-    return bread_slow(f, b, l);
+    return bread_slow(f, b, l, 0);
+}
+
+static inline uns breadb(struct fastbuf *f, void *b, uns l)
+{
+  if (f->bptr + l <= f->bstop)
+    {
+      memcpy(b, f->bptr, l);
+      f->bptr += l;
+      return l;
+    }
+  else
+    return bread_slow(f, b, l, 1);
 }
 
 void bwrite_slow(struct fastbuf *f, void *b, uns l);