WMII Reforge  Artifact [862bdfed80]

Artifact 862bdfed801afdae60ac1a7e32b522344597909e0b97f5ef9d5b3a3c63fd9b93:

  • File lib/libbio/bvprint.c — part of check-in [15eae1e8e6] at 2019-06-20 16:42:23 on branch trunk — Import sources to have something to work with (user: KhazAkar size: 626)

#include "plan9.h"
#include <bio.h>

static int
fmtBflush(Fmt *f)
{
	Biobuf *bp;

	bp = f->farg;
	bp->ocount = (char*)f->to - (char*)f->stop;
	if(Bflush(bp) < 0)
		return 0;
	f->stop = bp->ebuf;
	f->to = (char*)f->stop + bp->ocount;
	f->start = f->to;
	return 1;
}

int
Bvprint(Biobuf *bp, const char *fmt, va_list arg)
{
	int n;
	Fmt f;

	f.runes = 0;
	f.stop = bp->ebuf;
	f.start = (char*)f.stop + bp->ocount;
	f.to = f.start;
	f.flush = fmtBflush;
	f.farg = bp;
	f.nfmt = 0;
	fmtlocaleinit(&f, nil, nil, nil);
	n = fmtvprint(&f, fmt, arg);
	bp->ocount = (char*)f.to - (char*)f.stop;
	if(n == 0)
		n = f.nfmt;
	return n;
}