X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffastbuf.c;h=f83b40210132db4a87258d9d77f9078f0465b6bd;hb=8ab69f51fccccbcae521bd7f7e3ae27146fd1217;hp=0929f101a9c8a959bda89abe1c892711fe643051;hpb=49798253e0734806ffc02b11056a96da186a1bd6;p=libucw.git diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 0929f101..f83b4021 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -1,7 +1,7 @@ /* - * Sherlock Library -- Fast Buffered I/O + * UCW Library -- Fast Buffered I/O * - * (c) 1997--2000 Martin Mares + * (c) 1997--2005 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -335,3 +335,38 @@ bconfig(struct fastbuf *f, uns item, int value) { return f->config ? f->config(f, item, value) : -1; } + +void +brewind(struct fastbuf *f) +{ + bflush(f); + bsetpos(f, 0); +} + +int +bskip_slow(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; +}