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