diff options
| author | Steven Rostedt <srostedt@redhat.com> | 2009-11-30 16:00:28 -0500 |
|---|---|---|
| committer | Steven Rostedt <rostedt@goodmis.org> | 2009-11-30 16:00:28 -0500 |
| commit | 1f1ffab1f4dcc5e653a97a28521cd534a3fc79d5 (patch) | |
| tree | 93fd109b73e056c90606a9035b6186fd51c70b3b | |
| parent | cd58c5549fe71f2589a1dd95178fa9b78aef573f (diff) | |
Add weak versions of die, malloc_or_die and some others
The trace-cmd code defines die, malloc_or_die, warning and
big_endian. There are currently used by pevent code. This patch adds
them to the tracecmd library as weak functions.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
| -rw-r--r-- | trace-util.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/trace-util.c b/trace-util.c index 542e712..fbdb071 100644 --- a/trace-util.c +++ b/trace-util.c | |||
| @@ -13,6 +13,62 @@ | |||
| 13 | 13 | ||
| 14 | #define PLUGIN_DIR ".trace-cmd/plugins" | 14 | #define PLUGIN_DIR ".trace-cmd/plugins" |
| 15 | 15 | ||
| 16 | #define __weak __attribute__((weak)) | ||
| 17 | |||
| 18 | void __weak die(char *fmt, ...) | ||
| 19 | { | ||
| 20 | va_list ap; | ||
| 21 | int ret = errno; | ||
| 22 | |||
| 23 | if (errno) | ||
| 24 | perror("trace-cmd"); | ||
| 25 | else | ||
| 26 | ret = -1; | ||
| 27 | |||
| 28 | va_start(ap, fmt); | ||
| 29 | fprintf(stderr, " "); | ||
| 30 | vfprintf(stderr, fmt, ap); | ||
| 31 | va_end(ap); | ||
| 32 | |||
| 33 | fprintf(stderr, "\n"); | ||
| 34 | exit(ret); | ||
| 35 | } | ||
| 36 | |||
| 37 | void __weak warning(char *fmt, ...) | ||
| 38 | { | ||
| 39 | va_list ap; | ||
| 40 | |||
| 41 | if (errno) | ||
| 42 | perror("trace-cmd"); | ||
| 43 | errno = 0; | ||
| 44 | |||
| 45 | va_start(ap, fmt); | ||
| 46 | fprintf(stderr, " "); | ||
| 47 | vfprintf(stderr, fmt, ap); | ||
| 48 | va_end(ap); | ||
| 49 | |||
| 50 | fprintf(stderr, "\n"); | ||
| 51 | } | ||
| 52 | |||
| 53 | void __weak *malloc_or_die(unsigned int size) | ||
| 54 | { | ||
| 55 | void *data; | ||
| 56 | |||
| 57 | data = malloc(size); | ||
| 58 | if (!data) | ||
| 59 | die("malloc"); | ||
| 60 | return data; | ||
| 61 | } | ||
| 62 | |||
| 63 | int __weak bigendian(void) | ||
| 64 | { | ||
| 65 | unsigned char str[] = { 0x1, 0x2, 0x3, 0x4 }; | ||
| 66 | unsigned int *ptr; | ||
| 67 | |||
| 68 | ptr = (unsigned int *)str; | ||
| 69 | return *ptr == 0x01020304; | ||
| 70 | } | ||
| 71 | |||
| 16 | void parse_cmdlines(char *file, int size __unused) | 72 | void parse_cmdlines(char *file, int size __unused) |
| 17 | { | 73 | { |
| 18 | char *comm; | 74 | char *comm; |
