Steven Rostedt (VMware) | 6ab025e | 2018-08-16 11:10:15 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: LGPL-2.1 */ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 4 | * |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __UTIL_H |
| 7 | #define __UTIL_H |
| 8 | |
| 9 | #include <ctype.h> |
| 10 | |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 11 | /* Can be overridden */ |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 12 | void warning(const char *fmt, ...); |
| 13 | void pr_stat(const char *fmt, ...); |
| 14 | void vpr_stat(const char *fmt, va_list ap); |
| 15 | |
| 16 | /* Always available */ |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 17 | void __warning(const char *fmt, ...); |
| 18 | void __pr_stat(const char *fmt, ...); |
| 19 | |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 20 | void __vwarning(const char *fmt, ...); |
| 21 | void __vpr_stat(const char *fmt, ...); |
| 22 | |
Namhyung Kim | e1aa7c3 | 2012-08-22 16:00:31 +0900 | [diff] [blame] | 23 | #define min(x, y) ({ \ |
| 24 | typeof(x) _min1 = (x); \ |
| 25 | typeof(y) _min2 = (y); \ |
| 26 | (void) (&_min1 == &_min2); \ |
| 27 | _min1 < _min2 ? _min1 : _min2; }) |
| 28 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 29 | static inline char *strim(char *string) |
| 30 | { |
| 31 | char *ret; |
| 32 | |
| 33 | if (!string) |
| 34 | return NULL; |
| 35 | while (*string) { |
| 36 | if (!isspace(*string)) |
| 37 | break; |
| 38 | string++; |
| 39 | } |
| 40 | ret = string; |
| 41 | |
| 42 | string = ret + strlen(ret) - 1; |
| 43 | while (string > ret) { |
| 44 | if (!isspace(*string)) |
| 45 | break; |
| 46 | string--; |
| 47 | } |
| 48 | string[1] = 0; |
| 49 | |
| 50 | return ret; |
| 51 | } |
| 52 | |
| 53 | static inline int has_text(const char *text) |
| 54 | { |
| 55 | if (!text) |
| 56 | return 0; |
| 57 | |
| 58 | while (*text) { |
| 59 | if (!isspace(*text)) |
| 60 | return 1; |
| 61 | text++; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | #endif |