Linux 3.11-rc3
[cris-mirror.git] / tools / lib / traceevent / parse-utils.c
blobbba701cf10e6e28bf2efde0f2089c37131d88d01
1 /*
2 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation;
8 * version 2.1 of the License (not later!)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, see <http://www.gnu.org/licenses>
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include <errno.h>
26 #define __weak __attribute__((weak))
28 void __vdie(const char *fmt, va_list ap)
30 int ret = errno;
32 if (errno)
33 perror("trace-cmd");
34 else
35 ret = -1;
37 fprintf(stderr, " ");
38 vfprintf(stderr, fmt, ap);
40 fprintf(stderr, "\n");
41 exit(ret);
44 void __die(const char *fmt, ...)
46 va_list ap;
48 va_start(ap, fmt);
49 __vdie(fmt, ap);
50 va_end(ap);
53 void __weak die(const char *fmt, ...)
55 va_list ap;
57 va_start(ap, fmt);
58 __vdie(fmt, ap);
59 va_end(ap);
62 void __vwarning(const char *fmt, va_list ap)
64 if (errno)
65 perror("trace-cmd");
66 errno = 0;
68 fprintf(stderr, " ");
69 vfprintf(stderr, fmt, ap);
71 fprintf(stderr, "\n");
74 void __warning(const char *fmt, ...)
76 va_list ap;
78 va_start(ap, fmt);
79 __vwarning(fmt, ap);
80 va_end(ap);
83 void __weak warning(const char *fmt, ...)
85 va_list ap;
87 va_start(ap, fmt);
88 __vwarning(fmt, ap);
89 va_end(ap);
92 void __vpr_stat(const char *fmt, va_list ap)
94 vprintf(fmt, ap);
95 printf("\n");
98 void __pr_stat(const char *fmt, ...)
100 va_list ap;
102 va_start(ap, fmt);
103 __vpr_stat(fmt, ap);
104 va_end(ap);
107 void __weak vpr_stat(const char *fmt, va_list ap)
109 __vpr_stat(fmt, ap);
112 void __weak pr_stat(const char *fmt, ...)
114 va_list ap;
116 va_start(ap, fmt);
117 __vpr_stat(fmt, ap);
118 va_end(ap);
121 void __weak *malloc_or_die(unsigned int size)
123 void *data;
125 data = malloc(size);
126 if (!data)
127 die("malloc");
128 return data;