xref: /plan9/sys/src/libbio/bvprint.c (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include	<u.h>
2 #include	<libc.h>
3 #include	<bio.h>
4 
5 static int
fmtBflush(Fmt * f)6 fmtBflush(Fmt *f)
7 {
8 	Biobufhdr *bp;
9 
10 	bp = f->farg;
11 	bp->ocount = (char*)f->to - (char*)f->stop;
12 	if(Bflush(bp) < 0)
13 		return 0;
14 	f->stop = bp->ebuf;
15 	f->to = (char*)f->stop + bp->ocount;
16 	f->start = f->to;
17 	return 1;
18 }
19 
20 int
Bvprint(Biobufhdr * bp,char * fmt,va_list arg)21 Bvprint(Biobufhdr *bp, char *fmt, va_list arg)
22 {
23 	int n;
24 	Fmt f;
25 
26 	f.runes = 0;
27 	f.stop = bp->ebuf;
28 	f.start = (char*)f.stop + bp->ocount;
29 	f.to = f.start;
30 	f.flush = fmtBflush;
31 	f.farg = bp;
32 	f.nfmt = 0;
33 	f.args = arg;
34 	n = dofmt(&f, fmt);
35 	bp->ocount = (char*)f.to - (char*)f.stop;
36 	return n;
37 }
38