Blob


1 #include "lib9.h"
2 #include <bio.h>
4 static int
5 _Bfmtflush(Fmt *f)
6 {
7 Biobuf *b;
9 b = f->farg;
10 b->ocount = (char*)f->to - (char*)f->stop;
11 if(Bflush(b) < 0)
12 return 0;
13 f->to = b->ebuf+b->ocount;
14 return 1;
15 }
17 int
18 Bfmtinit(Fmt *f, Biobuf *b)
19 {
20 if(b->state != Bwactive)
21 return -1;
22 memset(f, 0, sizeof *f);
23 f->farg = b;
24 f->start = b->bbuf;
25 f->to = b->ebuf+b->ocount;
26 f->stop = b->ebuf;
27 f->flush = _Bfmtflush;
28 return 0;
29 }
31 int
32 Bfmtflush(Fmt *f)
33 {
34 Biobuf *b;
36 b = f->farg;
37 if(f->to == nil)
38 return -1;
39 b->ocount = (char*)f->to - (char*)f->stop;
40 return f->nfmt;
41 }