xref: /plan9-contrib/sys/src/cmd/unix/drawterm/libc/fmtfd.c (revision 781103c4074deb8af160e8a0da2742ba6b29dc2b)
1 #include <inttypes.h>
2 #include <u.h>
3 #include <libc.h>
4 #include "fmtdef.h"
5 
6 /*
7  * public routine for final flush of a formatting buffer
8  * to a file descriptor; returns total char count.
9  */
10 int
11 fmtfdflush(Fmt *f)
12 {
13 	if(__fmtFdFlush(f) <= 0)
14 		return -1;
15 	return f->nfmt;
16 }
17 
18 /*
19  * initialize an output buffer for buffered printing
20  */
21 int
22 fmtfdinit(Fmt *f, int fd, char *buf, int size)
23 {
24 	f->runes = 0;
25 	f->start = buf;
26 	f->to = buf;
27 	f->stop = buf + size;
28 	f->flush = __fmtFdFlush;
29 	f->farg = (void*)(uintptr_t)fd;
30 	f->nfmt = 0;
31 	return 0;
32 }
33