]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.c
Added special mode for sorting of regular files.
[libucw.git] / lib / fastbuf.c
index b7be624b5645d5ac34e1e52ca83b1ce2a951be62..0929f101a9c8a959bda89abe1c892711fe643051 100644 (file)
@@ -244,11 +244,11 @@ bgets(struct fastbuf *f, byte *b, uns l)
   int k;
 
   k = bgetc(f);
   int k;
 
   k = bgetc(f);
-  if (k == EOF)
+  if (k < 0)
     return NULL;
   while (b < e)
     {
     return NULL;
   while (b < e)
     {
-      if (k == '\n' || k == EOF)
+      if (k == '\n' || k < 0)
        {
          *b = 0;
          return b;
        {
          *b = 0;
          return b;
@@ -259,6 +259,29 @@ bgets(struct fastbuf *f, byte *b, uns l)
   die("%s: Line too long", f->name);
 }
 
   die("%s: Line too long", f->name);
 }
 
+int
+bgets_nodie(struct fastbuf *f, byte *b, uns l)
+{
+  byte *start = b;
+  byte *e = b + l - 1;
+  int k;
+
+  k = bgetc(f);
+  if (k < 0)
+    return 0;
+  while (b < e)
+    {
+      if (k == '\n' || k < 0)
+       {
+         *b++ = 0;
+         return b - start;
+       }
+      *b++ = k;
+      k = bgetc(f);
+    }
+  return -1;
+}
+
 byte *
 bgets0(struct fastbuf *f, byte *b, uns l)
 {
 byte *
 bgets0(struct fastbuf *f, byte *b, uns l)
 {
@@ -266,11 +289,11 @@ bgets0(struct fastbuf *f, byte *b, uns l)
   int k;
 
   k = bgetc(f);
   int k;
 
   k = bgetc(f);
-  if (k == EOF)
+  if (k < 0)
     return NULL;
   while (b < e)
     {
     return NULL;
   while (b < e)
     {
-      if (!k || k == EOF)
+      if (k <= 0)
        {
          *b = 0;
          return b;
        {
          *b = 0;
          return b;
@@ -291,14 +314,19 @@ bbcopy_slow(struct fastbuf *f, struct fastbuf *t, uns l)
 
       favail = bdirect_read_prepare(f, &fptr);
       if (!favail)
 
       favail = bdirect_read_prepare(f, &fptr);
       if (!favail)
-       die("bbcopy: source exhausted");
+       {
+         if (l == ~0U)
+           return;
+         die("bbcopy: source exhausted");
+       }
       tavail = bdirect_write_prepare(t, &tptr);
       n = MIN(l, favail);
       n = MIN(n, tavail);
       memcpy(tptr, fptr, n);
       bdirect_read_commit(f, fptr + n);
       bdirect_write_commit(t, tptr + n);
       tavail = bdirect_write_prepare(t, &tptr);
       n = MIN(l, favail);
       n = MIN(n, tavail);
       memcpy(tptr, fptr, n);
       bdirect_read_commit(f, fptr + n);
       bdirect_write_commit(t, tptr + n);
-      l -= n;
+      if (l != ~0U)
+       l -= n;
     }
 }
 
     }
 }