summaryrefslogtreecommitdiff
path: root/lib/libc/stdio/vasprintf.c
blob: 128d4ee32a7fed26edf472613369533a4d66a948 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <io.h>
#include <stdarg.h>
#include <stdio.h>

// TODO: maybe use memstream in future??
int vasprintf(char **restrict ptr, const char *restrict format, va_list ap)
{
	int l;
	va_list ap2;
	va_copy(ap2, ap);
	l = vsnprintf(0, 0, format, ap2);
	va_end(ap2);

	if (l < 0 || !(*ptr = malloc(l + 1U)))
		return -1;

	return vsnprintf(*ptr, l + 1U, format, ap);
}