xprintf.c 413 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <stdarg.h>

#include "../util.h"

size_t xvsnprintf(char *p, size_t len, const char *fmt, va_list ap)
{
	int ret;
	if ((ret = vsnprintf(p, len, fmt, ap)) >= len)
	{
		p[len-1] = 0;
		return len;
	}
	return ret;
}

size_t xsnprintf(char *p, size_t len, const char *fmt, ...)
{
	size_t ret;
	va_list ap;
	va_start(ap, fmt);
	ret = vsnprintf(p, len, fmt, ap);
	va_end(ap);
	return ret;
}