]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.c
Defined a GET_TAGGED_CHAR macro to read our internal representation
[libucw.git] / lib / fastbuf.c
index 5b394cf1c867c2f755b07db788a562ad3e3fb84c..00fa51bcccd902538514cbbb069598008094b06f 100644 (file)
@@ -187,7 +187,7 @@ void bput5_slow(struct fastbuf *f, u64 o)
 #endif
 }
 
 #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)
 {
   uns total = 0;
   while (l)
@@ -209,6 +209,8 @@ uns bread_slow(struct fastbuf *f, void *b, uns l)
       l -= k;
       total += k;
     }
       l -= k;
       total += k;
     }
+  if (check && total && l)
+    die("breadb: short read");
   return total;
 }
 
   return total;
 }
 
@@ -254,6 +256,28 @@ bgets(struct fastbuf *f, byte *b, uns l)
   die("%s: Line too long", f->name);
 }
 
   die("%s: Line too long", f->name);
 }
 
+byte *
+bgets0(struct fastbuf *f, byte *b, uns l)
+{
+  byte *e = b + l - 1;
+  int k;
+
+  k = bgetc(f);
+  if (k == EOF)
+    return NULL;
+  while (b < e)
+    {
+      if (!k || k == EOF)
+       {
+         *b = 0;
+         return b;
+       }
+      *b++ = k;
+      k = bgetc(f);
+    }
+  die("%s: Line too long", f->name);
+}
+
 int
 bdirect_read(struct fastbuf *f, byte **buf)
 {
 int
 bdirect_read(struct fastbuf *f, byte **buf)
 {