summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/subcmd-util.h
blob: 98fb9f9270eb9020c4293633fa4fc38e67033b64 (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
#ifndef __PERF_SUBCMD_UTIL_H
#define __PERF_SUBCMD_UTIL_H

#include <stdio.h>

#define astrcatf(out, fmt, ...)						\
({									\
	char *tmp = *(out);						\
	if (asprintf((out), "%s" fmt, tmp ?: "", ## __VA_ARGS__) == -1)	\
		die("asprintf failed");					\
	free(tmp);							\
})

static inline void astrcat(char **out, const char *add)
{
	char *tmp = *out;

	if (asprintf(out, "%s%s", tmp ?: "", add) == -1)
		die("asprintf failed");

	free(tmp);
}

#endif /* __PERF_SUBCMD_UTIL_H */