xref: /inferno-os/libbio/bprint.c (revision 9dbf735d35c339c90deaed43fc0ae17f16c122f7)
1 #include	"lib9.h"
2 #include	<bio.h>
3 
4 int
5 Bprint(Biobuf *bp, char *fmt, ...)
6 {
7 	va_list	ap;
8 	char *ip, *ep, *out;
9 	int n;
10 
11 	ep = (char*)bp->ebuf;
12 	ip = ep + bp->ocount;
13 	va_start(ap, fmt);
14 	out = vseprint(ip, ep, fmt, ap);
15 	va_end(ap);
16 	if(out == nil || out >= ep-5) {
17 		if(Bflush(bp) < 0)
18 			return Beof;
19 		ip = ep + bp->ocount;
20 		va_start(ap, fmt);
21 		out = vseprint(ip, ep, fmt, ap);
22 		va_end(ap);
23 		if(out == nil || out >= ep-5)
24 			return Beof;
25 	}
26 	n = out-ip;
27 	bp->ocount += n;
28 	return n;
29 }
30