summaryrefslogtreecommitdiff
path: root/tools/perf/util/subcmd-util.h
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2015-12-15 09:39:36 -0600
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-12-16 21:33:13 -0300
commit901421a5bdf605d24c278825cdd032cd6038bcb8 (patch)
treee38d011aa6ff9c348a6ea7d3c9e664fef54b237f /tools/perf/util/subcmd-util.h
parent096d35585b4fce7d3ee9b8b34314f39f49491ab1 (diff)
downloadlinux-901421a5bdf605d24c278825cdd032cd6038bcb8.tar.gz
linux-901421a5bdf605d24c278825cdd032cd6038bcb8.tar.bz2
linux-901421a5bdf605d24c278825cdd032cd6038bcb8.zip
perf tools: Remove subcmd dependencies on strbuf
Introduce and use new astrcat() and astrcatf() functions which replace the strbuf functionality for subcmd. For now they duplicate strbuf's die-on-allocation-error policy. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/957d207e1254406fa11fc2e405e75a7e405aad8f.1450193761.git.jpoimboe@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/subcmd-util.h')
-rw-r--r--tools/perf/util/subcmd-util.h24
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 */