aboutsummaryrefslogtreecommitdiff
path: root/src/libbio/bfmt.c
blob: 4e0b6206765269284c8d27a0a6cc900beba51b25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "lib9.h"
#include <bio.h>

static int
_Bfmtflush(Fmt *f)
{
	Biobuf *b;

	b = f->farg;
	b->ocount = (char*)f->to - (char*)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;
}