From 25d1c51565706f7d9e2a8cec31a80dd32c2c889b Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Tue, 6 Apr 2010 14:39:06 -0400 Subject: parse-events: Move parse-event utils to separate file Move the util functions used by parse-events into a separate file and compile it with the libparsevents library. Also add "__die()" equivalent functions that are always available. Signed-off-by: Steven Rostedt --- parse-utils.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 parse-utils.c (limited to 'parse-utils.c') diff --git a/parse-utils.c b/parse-utils.c new file mode 100644 index 0000000..103bbd8 --- /dev/null +++ b/parse-utils.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include + +#define __weak __attribute__((weak)) + +void __vdie(char *fmt, va_list ap) +{ + int ret = errno; + + if (errno) + perror("trace-cmd"); + else + ret = -1; + + fprintf(stderr, " "); + vfprintf(stderr, fmt, ap); + + fprintf(stderr, "\n"); + exit(ret); +} + +void __die(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vdie(fmt, ap); + va_end(ap); +} + +void __weak die(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vdie(fmt, ap); + va_end(ap); +} + +void __vwarning(char *fmt, va_list ap) +{ + if (errno) + perror("trace-cmd"); + errno = 0; + + fprintf(stderr, " "); + vfprintf(stderr, fmt, ap); + + fprintf(stderr, "\n"); +} + +void __warning(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vwarning(fmt, ap); + va_end(ap); +} + +void __weak warning(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vwarning(fmt, ap); + va_end(ap); +} + +void __vpr_stat(char *fmt, va_list ap) +{ + vprintf(fmt, ap); + printf("\n"); +} + +void __pr_stat(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vpr_stat(fmt, ap); + va_end(ap); +} + +void __weak pr_stat(char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + __vpr_stat(fmt, ap); + va_end(ap); +} + +void __weak *malloc_or_die(unsigned int size) +{ + void *data; + + data = malloc(size); + if (!data) + die("malloc"); + return data; +} -- cgit v1.2.2