1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3 * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <[email protected]>
4 *
5 */
6 #ifndef __TEP_EVENT_UTIL_H
7 #define __TEP_EVENT_UTIL_H
8
9 #include <ctype.h>
10 #include <stdarg.h>
11 #include <stdbool.h>
12
13 #include "event-parse.h"
14
15 void tep_warning(const char *fmt, ...);
16 void tep_info(const char *fmt, ...);
17
18 /* Can be overridden */
19 int tep_vprint(const char *name, enum tep_loglevel level,
20 bool print_err, const char *fmt, va_list ap);
21
22 /* The actual call of tep_vprint() for overrides to use */
23 int __tep_vprint(const char *name, enum tep_loglevel level,
24 bool print_err, const char *fmt, va_list ap);
25
26
27 #define __deprecated(msg) __attribute__((deprecated("msg")))
28
29 /* For backward compatibilty, do not use */
30 int tep_vwarning(const char *name, const char *fmt, va_list ap) __deprecated(Use tep_vprint instead);
31 void pr_stat(const char *fmt, ...) __deprecated(Use tep_info instead);
32 void vpr_stat(const char *fmt, va_list ap) __deprecated(Use tep_vprint instead);
33 void __pr_stat(const char *fmt, ...) __deprecated(Use tep_info instead);;
34 void __vpr_stat(const char *fmt, va_list ap) __deprecated(Use tep_vprint instead);;
35
36 #define min(x, y) ({ \
37 typeof(x) _min1 = (x); \
38 typeof(y) _min2 = (y); \
39 (void) (&_min1 == &_min2); \
40 _min1 < _min2 ? _min1 : _min2; })
41
strim(char * string)42 static inline char *strim(char *string)
43 {
44 char *ret;
45
46 if (!string)
47 return NULL;
48 while (*string) {
49 if (!isspace(*string))
50 break;
51 string++;
52 }
53 ret = string;
54
55 string = ret + strlen(ret) - 1;
56 while (string > ret) {
57 if (!isspace(*string))
58 break;
59 string--;
60 }
61 string[1] = 0;
62
63 return ret;
64 }
65
has_text(const char * text)66 static inline int has_text(const char *text)
67 {
68 if (!text)
69 return 0;
70
71 while (*text) {
72 if (!isspace(*text))
73 return 1;
74 text++;
75 }
76
77 return 0;
78 }
79
80 #endif
81