]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.c
Added bopen_tmp() for opening of temporary files.
[libucw.git] / lib / fastbuf.c
index e9de62df425c9f1cf20c437eafa29205c8c1bfcb..1b039c6ca7e32fb69a1f1a8467f35bf4ec7f0550 100644 (file)
@@ -80,20 +80,26 @@ int bpeekc_slow(struct fastbuf *f)
   return *f->bptr;
 }
 
-void bputc_slow(struct fastbuf *f, byte c)
+void bputc_slow(struct fastbuf *f, uns c)
 {
   if (f->bptr >= f->bufend)
     f->spout(f);
   *f->bptr++ = c;
 }
 
-word bgetw_slow(struct fastbuf *f)
+int bgetw_slow(struct fastbuf *f)
 {
-  word w = bgetc_slow(f);
+  int w1, w2;
+  w1 = bgetc_slow(f);
+  if (w1 < 0)
+    return w1;
+  w2 = bgetc_slow(f);
+  if (w2 < 0)
+    return w2;
 #ifdef CPU_BIG_ENDIAN
-  return (w << 8) | bgetc_slow(f);
+  return (w1 << 8) | w2;
 #else
-  return w | (bgetc_slow(f) << 8);
+  return w1 | (w2 << 8);
 #endif
 }
 
@@ -137,7 +143,7 @@ u64 bget5_slow(struct fastbuf *f)
   return ((u64) h << 32) | l;
 }
 
-void bputw_slow(struct fastbuf *f, word w)
+void bputw_slow(struct fastbuf *f, uns w)
 {
 #ifdef CPU_BIG_ENDIAN
   bputc_slow(f, w >> 8);
@@ -209,7 +215,7 @@ uns bread_slow(struct fastbuf *f, void *b, uns l, uns check)
       l -= k;
       total += k;
     }
-  if (check && total && total != l)
+  if (check && total && l)
     die("breadb: short read");
   return total;
 }
@@ -256,6 +262,28 @@ bgets(struct fastbuf *f, byte *b, uns l)
   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)
 {