diff options
Diffstat (limited to 'tools/perf/util/subcmd-util.h')
-rw-r--r-- | tools/perf/util/subcmd-util.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h new file mode 100644 index 000000000000..98fb9f9270eb --- /dev/null +++ b/tools/perf/util/subcmd-util.h @@ -0,0 +1,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 */ |