plan9port/src/libbio/bfmt.c

42 lines
577 B
C
Raw Normal View History

2003-12-03 22:51:11 +00:00
#include "lib9.h"
#include <bio.h>
static int
_Bfmtflush(Fmt *f)
{
Biobuf *b;
b = f->farg;
b->ocount = (char*)f->to - (char*)f->stop;
2003-12-03 22:51:11 +00:00
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)
{
2004-04-25 21:13:58 +00:00
Biobuf *b;
b = f->farg;
if(f->to == nil)
2003-12-03 22:51:11 +00:00
return -1;
2004-04-25 21:13:58 +00:00
b->ocount = (char*)f->to - (char*)f->stop;
2003-12-03 22:51:11 +00:00
return f->nfmt;
}