xref: /plan9-contrib/sys/src/libbio/bprint.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include	<u.h>
2 #include	<libc.h>
3 #include	<bio.h>
4 
5 #define	DOTDOT	(&fmt+1)
6 int	printcol;
7 
8 int
9 Bprint(Biobufhdr *bp, char *fmt, ...)
10 {
11 	char *ip, *ep, *out;
12 	int n, pcol;
13 
14 	ep = (char*)bp->ebuf;
15 	ip = ep + bp->ocount;
16 	pcol = printcol;
17 	out = doprint(ip, ep, fmt, DOTDOT);
18 	if(out >= ep-5) {
19 		Bflush(bp);
20 		ip = ep + bp->ocount;
21 		printcol = pcol;
22 		out = doprint(ip, ep, fmt, DOTDOT);
23 		if(out >= ep-5)
24 			return Beof;
25 	}
26 	n = out-ip;
27 	bp->ocount += n;
28 	return n;
29 }
30