commit b0be3b88261ddf09aaeca5c287f1b9ca26ccb558 from: rsc date: Wed Dec 03 22:51:11 2003 UTC add bfmt. commit - 669250d159e93a6933afa4cd25f410af801515ec commit + b0be3b88261ddf09aaeca5c287f1b9ca26ccb558 blob - /dev/null blob + f1b6f5ab817e6a5308df74a21c6980b1c1bef840 (mode 644) --- /dev/null +++ src/libbio/bfmt.c @@ -0,0 +1,37 @@ +#include "lib9.h" +#include + +static int +_Bfmtflush(Fmt *f) +{ + Biobuf *b; + + b = f->farg; + b->ocount = f->to - f->stop; + if(Bflush(b) < 0) + return 0; + f->to = b->ebuf+b->ocount; + return 1; +} + +int +Bfmtinit(Fmt *f, Biobuf *b) +{ + if(b->state != Bwactive) + return -1; + memset(f, 0, sizeof *f); + f->farg = b; + f->start = b->bbuf; + f->to = b->ebuf+b->ocount; + f->stop = b->ebuf; + f->flush = _Bfmtflush; + return 0; +} + +int +Bfmtflush(Fmt *f) +{ + if(_Bfmtflush(f) <= 0) + return -1; + return f->nfmt; +}