Merge tag 'metag-for-v3.12' of git://git.kernel.org/pub/scm/linux/kernel/git/jhogan...
[linux-drm-fsl-dcu.git] / tools / lib / traceevent / parse-utils.c
1 /*
2  * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
3  *
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!)
9  *
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.
14  *
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>
17  *
18  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19  */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include <errno.h>
25
26 #define __weak __attribute__((weak))
27
28 void __vdie(const char *fmt, va_list ap)
29 {
30         int ret = errno;
31
32         if (errno)
33                 perror("trace-cmd");
34         else
35                 ret = -1;
36
37         fprintf(stderr, "  ");
38         vfprintf(stderr, fmt, ap);
39
40         fprintf(stderr, "\n");
41         exit(ret);
42 }
43
44 void __die(const char *fmt, ...)
45 {
46         va_list ap;
47
48         va_start(ap, fmt);
49         __vdie(fmt, ap);
50         va_end(ap);
51 }
52
53 void __weak die(const char *fmt, ...)
54 {
55         va_list ap;
56
57         va_start(ap, fmt);
58         __vdie(fmt, ap);
59         va_end(ap);
60 }
61
62 void __vwarning(const char *fmt, va_list ap)
63 {
64         if (errno)
65                 perror("trace-cmd");
66         errno = 0;
67
68         fprintf(stderr, "  ");
69         vfprintf(stderr, fmt, ap);
70
71         fprintf(stderr, "\n");
72 }
73
74 void __warning(const char *fmt, ...)
75 {
76         va_list ap;
77
78         va_start(ap, fmt);
79         __vwarning(fmt, ap);
80         va_end(ap);
81 }
82
83 void __weak warning(const char *fmt, ...)
84 {
85         va_list ap;
86
87         va_start(ap, fmt);
88         __vwarning(fmt, ap);
89         va_end(ap);
90 }
91
92 void __vpr_stat(const char *fmt, va_list ap)
93 {
94         vprintf(fmt, ap);
95         printf("\n");
96 }
97
98 void __pr_stat(const char *fmt, ...)
99 {
100         va_list ap;
101
102         va_start(ap, fmt);
103         __vpr_stat(fmt, ap);
104         va_end(ap);
105 }
106
107 void __weak vpr_stat(const char *fmt, va_list ap)
108 {
109         __vpr_stat(fmt, ap);
110 }
111
112 void __weak pr_stat(const char *fmt, ...)
113 {
114         va_list ap;
115
116         va_start(ap, fmt);
117         __vpr_stat(fmt, ap);
118         va_end(ap);
119 }
120
121 void __weak *malloc_or_die(unsigned int size)
122 {
123         void *data;
124
125         data = malloc(size);
126         if (!data)
127                 die("malloc");
128         return data;
129 }