/*
* Sherlock Library -- Fast Buffered I/O
*
- * (c) 1997--2000 Martin Mares <mj@ucw.cz>
+ * (c) 1997--2004 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
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);
- l -= n;
+ if (l != ~0U)
+ l -= n;
}
}
{
return f->config ? f->config(f, item, value) : -1;
}
+
+void
+brewind(struct fastbuf *f)
+{
+ bflush(f);
+ bsetpos(f, 0);
+}
+
+int
+bskip(struct fastbuf *f, uns len)
+{
+ while (len)
+ {
+ byte *buf;
+ uns l = bdirect_read_prepare(f, &buf);
+ if (!l)
+ return 0;
+ l = MIN(l, len);
+ bdirect_read_commit(f, buf+l);
+ len -= l;
+ }
+ return 1;
+}
+
+sh_off_t
+bfilesize(struct fastbuf *f)
+{
+ if (!f)
+ return 0;
+ sh_off_t pos = btell(f);
+ bseek(f, 0, SEEK_END);
+ sh_off_t len = btell(f);
+ bsetpos(f, pos);
+ return len;
+}