43 lines · 940 B · C
RawDownload
/*  * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include <u.h>#include <libc.h>#include "fmtdef.h" /* * generic routine for flushing a formatting buffer * to a file descriptor */int_fmtFdFlush(Fmt *f){	int n; 	n = (char*)f->to - (char*)f->start;	if(n && write((int)(uintptr)f->farg, f->start, n) != n)		return 0;	f->to = f->start;	return 1;} intvfprint(int fd, char *fmt, va_list args){	Fmt f;	char buf[256];	int n; 	fmtfdinit(&f, fd, buf, sizeof(buf));	f.args = args;	n = dofmt(&f, fmt);	if(n > 0 && _fmtFdFlush(&f) == 0)		return -1;	return n;}