Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 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 |
Jon Stanley | 7b9f6b4 | 2012-09-07 16:32:46 -0400 | [diff] [blame] | 16 | * License along with this program; if not, see <http://www.gnu.org/licenses> |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 17 | * |
| 18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 19 | */ |
| 20 | #ifndef __UTIL_H |
| 21 | #define __UTIL_H |
| 22 | |
| 23 | #include <ctype.h> |
| 24 | |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 25 | /* Can be overridden */ |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 26 | void warning(const char *fmt, ...); |
| 27 | void pr_stat(const char *fmt, ...); |
| 28 | void vpr_stat(const char *fmt, va_list ap); |
| 29 | |
| 30 | /* Always available */ |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 31 | void __warning(const char *fmt, ...); |
| 32 | void __pr_stat(const char *fmt, ...); |
| 33 | |
Steven Rostedt | 668fe01 | 2012-04-06 00:47:55 +0200 | [diff] [blame] | 34 | void __vwarning(const char *fmt, ...); |
| 35 | void __vpr_stat(const char *fmt, ...); |
| 36 | |
Namhyung Kim | e1aa7c3 | 2012-08-22 16:00:31 +0900 | [diff] [blame] | 37 | #define min(x, y) ({ \ |
| 38 | typeof(x) _min1 = (x); \ |
| 39 | typeof(y) _min2 = (y); \ |
| 40 | (void) (&_min1 == &_min2); \ |
| 41 | _min1 < _min2 ? _min1 : _min2; }) |
| 42 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 43 | static inline char *strim(char *string) |
| 44 | { |
| 45 | char *ret; |
| 46 | |
| 47 | if (!string) |
| 48 | return NULL; |
| 49 | while (*string) { |
| 50 | if (!isspace(*string)) |
| 51 | break; |
| 52 | string++; |
| 53 | } |
| 54 | ret = string; |
| 55 | |
| 56 | string = ret + strlen(ret) - 1; |
| 57 | while (string > ret) { |
| 58 | if (!isspace(*string)) |
| 59 | break; |
| 60 | string--; |
| 61 | } |
| 62 | string[1] = 0; |
| 63 | |
| 64 | return ret; |
| 65 | } |
| 66 | |
| 67 | static inline int has_text(const char *text) |
| 68 | { |
| 69 | if (!text) |
| 70 | return 0; |
| 71 | |
| 72 | while (*text) { |
| 73 | if (!isspace(*text)) |
| 74 | return 1; |
| 75 | text++; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | #endif |