aboutsummaryrefslogtreecommitdiff
path: root/util.cpp
blob: 04354dbfef3b827a11e65a3cab1b60eba6e3ff01 (plain)
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
26
#include <cstdio>
#include <cstdarg>

#include "util.h"

using namespace std;

string stringf(const char * fmt, ...) {
	va_list args, args_copy;
	va_start(args, fmt);
	va_copy(args_copy, args);

	size_t sz = vsnprintf(NULL, 0, fmt, args_copy) + 1;
	char * msg = (char *) malloc(sz);
	va_end(args_copy);

	vsnprintf(msg, sz, fmt, args);

	string out = msg;
	free(msg);

	va_end(args);

	return out;
}