xref: /plan9/sys/src/cmd/unix/drawterm/libc/fmtfd.c (revision 2282df4ee19682a10ae95200202320ff2912f104)
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
fmtfdflush(Fmt * f)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
fmtfdinit(Fmt * f,int fd,char * buf,int size)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