* (c) 1997--2000 Martin Mares <mj@ucw.cz>
*/
-#include <stdio.h>
-#include <stdlib.h>
-
#include "lib/lib.h"
#include "lib/fastbuf.h"
+#include <stdio.h>
+#include <stdlib.h>
+
void bclose(struct fastbuf *f)
{
bflush(f);
f->close(f);
- free(f);
+ xfree(f);
}
void bflush(struct fastbuf *f)
#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;
f->refill(f);
k = f->bstop - f->bptr;
if (!k)
- die("bread on %s: file exhausted", f->name);
+ break;
}
if (k > l)
k = l;
f->bptr += k;
b = (byte *)b + k;
l -= k;
+ total += k;
}
+ return total;
}
void bwrite_slow(struct fastbuf *f, void *b, uns l)