2015-12-22 12:55:44 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
2016-11-25 17:18:40 +01:00
|
|
|
if(n && write((int)(uintptr_t)f->farg, f->start, n) != n)
|
2015-12-22 12:55:44 +01:00
|
|
|
return 0;
|
|
|
|
f->to = f->start;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_vfprint(int fd, const char *fmt, va_list args)
|
2015-12-22 12:55:44 +01:00
|
|
|
{
|
|
|
|
Fmt f;
|
|
|
|
char buf[256];
|
|
|
|
int n;
|
|
|
|
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_fmtfdinit(&f, fd, buf, sizeof(buf));
|
2015-12-22 12:55:44 +01:00
|
|
|
//f.args = args;
|
|
|
|
va_copy(f.args,args);
|
2017-04-19 23:33:14 +02:00
|
|
|
n = jehanne_dofmt(&f, fmt);
|
2015-12-22 12:55:44 +01:00
|
|
|
va_end(f.args);
|
|
|
|
if(n > 0 && _fmtFdFlush(&f) == 0)
|
|
|
|
return -1;
|
|
|
|
return n;
|
|
|
|
}
|