summaryrefslogtreecommitdiffstats
path: root/src/lib.c
blob: 85638731f3b2477c8e09c5a8a8e2b0f36763d4b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
int smprintf(char ** str, const char * format, ...) { /* allocates automaticalls (: */
	va_list ap, aq;
	va_start(ap, format);
	va_copy(aq, ap);
	int len = vsnprintf(NULL, 0, format, ap);
	*str = malloc(len+1);
	if (len != vsprintf(str, format, ap))
		fprintf(stderr, "[BUG] !!! len1 != len2\n");
	va_end(ap);
	va_end(aq);
	return len;
}