X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffastbuf.c;h=00fa51bcccd902538514cbbb069598008094b06f;hb=91373ee6489fbe08db12bef2cf6df704b31e1378;hp=1895e9bd5d892893135f348dd1312a8ca377279c;hpb=753302b5281e6ed889cfd1ed755a7104cc421802;p=libucw.git diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 1895e9bd..00fa51bc 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -187,7 +187,7 @@ void bput5_slow(struct fastbuf *f, u64 o) #endif } -uns bread_slow(struct fastbuf *f, void *b, uns l) +uns bread_slow(struct fastbuf *f, void *b, uns l, uns check) { uns total = 0; while (l) @@ -209,6 +209,8 @@ uns bread_slow(struct fastbuf *f, void *b, uns l) l -= k; total += k; } + if (check && total && l) + die("breadb: short read"); return total; } @@ -253,3 +255,53 @@ bgets(struct fastbuf *f, byte *b, uns l) } die("%s: Line too long", f->name); } + +byte * +bgets0(struct fastbuf *f, byte *b, uns l) +{ + byte *e = b + l - 1; + int k; + + k = bgetc(f); + if (k == EOF) + return NULL; + while (b < e) + { + if (!k || k == EOF) + { + *b = 0; + return b; + } + *b++ = k; + k = bgetc(f); + } + die("%s: Line too long", f->name); +} + +int +bdirect_read(struct fastbuf *f, byte **buf) +{ + int len; + + if (f->bptr == f->bstop && !f->refill(f)) + return EOF; + *buf = f->bptr; + len = f->bstop - f->bptr; + f->bptr += len; + return len; +} + +int +bdirect_write_prepare(struct fastbuf *f, byte **buf) +{ + if (f->bptr == f->bufend) + f->spout(f); + *buf = f->bptr; + return f->bufend - f->bptr; +} + +void +bdirect_write_commit(struct fastbuf *f, byte *pos) +{ + f->bptr = pos; +}