X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Ffastbuf.c;h=013c1b0848d3453672c38828c24bc91a4a8d09c4;hb=3f29125f27f7ee82281e49fef16ad32811cc3dcc;hp=00fa51bcccd902538514cbbb069598008094b06f;hpb=8d7ea15cf2d519e6f6cae540bdaeeee7fbc82acc;p=libucw.git diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 00fa51bc..013c1b08 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -2,6 +2,9 @@ * Sherlock Library -- Fast Buffered I/O * * (c) 1997--2000 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #include "lib/lib.h" @@ -80,20 +83,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 +146,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); @@ -279,7 +288,7 @@ bgets0(struct fastbuf *f, byte *b, uns l) } int -bdirect_read(struct fastbuf *f, byte **buf) +bdirect_read_prepare(struct fastbuf *f, byte **buf) { int len; @@ -287,10 +296,15 @@ bdirect_read(struct fastbuf *f, byte **buf) return EOF; *buf = f->bptr; len = f->bstop - f->bptr; - f->bptr += len; return len; } +void +bdirect_read_commit(struct fastbuf *f, byte *pos) +{ + f->bptr = pos; +} + int bdirect_write_prepare(struct fastbuf *f, byte **buf) {