shithub: scc

ref: 5ac3a0d4c1a9d7e4d3912c4770084b885007aca6
dir: /src/libc/stdio/vsnprintf.c/

View raw version
#include <stdarg.h>
#include <stdio.h>

#undef vsnprintf

int
vsnprintf(char *restrict s, size_t siz, const char *restrict fmt, va_list ap)
{
	FILE f;
	int r;

	f.flags = _IORW | _IOSTRG;
	f.len = siz;
	f.buf = s;
	f.wp = s;
	f.rp = s + siz;

	r = vfprintf(&f, fmt, ap);
	if (s) {
		if (f.wp == f.rp)
			--f.wp;
		if (siz != 0)
			*f.wp = '\0';
	}

	return r;
}