xref: /plan9/sys/src/cmd/unix/drawterm/libc/fmtfdflush.c (revision 2282df4ee19682a10ae95200202320ff2912f104)
1 #include <inttypes.h>
2 #include <u.h>
3 #include <libc.h>
4 #include "fmtdef.h"
5 
6 /*
7  * generic routine for flushing a formatting buffer
8  * to a file descriptor
9  */
10 int
__fmtFdFlush(Fmt * f)11 __fmtFdFlush(Fmt *f)
12 {
13 	int n;
14 
15 	n = (char*)f->to - (char*)f->start;
16 	if(n && write((uintptr_t)f->farg, f->start, n) != n)
17 		return 0;
18 	f->to = f->start;
19 	return 1;
20 }
21