summaryrefslogtreecommitdiffstats
path: root/src/lib.c
blob: de78be0dbc479beeb6bacb5e18538f1e37ade30f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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);
	if (!(*str = realloc(*str, len+1)))
		fprintf(stderr, "[BUG] !!! realloc failed\n");
	if (len != vsprintf(*str, format, ap))
		fprintf(stderr, "[BUG] !!! len1 != len2\n");
	va_end(ap);
	va_end(aq);
	return len;
}
char * startswith (char * testiranec, char * začetek) {
	if (!strncmp(testiranec, začetek, strlen(začetek)))
		return testiranec+strlen(začetek);
	return NULL;
}