at v3.13-rc6 85 lines 2.0 kB view raw
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#ifndef __UTIL_H 21#define __UTIL_H 22 23#include <ctype.h> 24 25/* Can be overridden */ 26void die(const char *fmt, ...); 27void *malloc_or_die(unsigned int size); 28void warning(const char *fmt, ...); 29void pr_stat(const char *fmt, ...); 30void vpr_stat(const char *fmt, va_list ap); 31 32/* Always available */ 33void __die(const char *fmt, ...); 34void __warning(const char *fmt, ...); 35void __pr_stat(const char *fmt, ...); 36 37void __vdie(const char *fmt, ...); 38void __vwarning(const char *fmt, ...); 39void __vpr_stat(const char *fmt, ...); 40 41#define min(x, y) ({ \ 42 typeof(x) _min1 = (x); \ 43 typeof(y) _min2 = (y); \ 44 (void) (&_min1 == &_min2); \ 45 _min1 < _min2 ? _min1 : _min2; }) 46 47static inline char *strim(char *string) 48{ 49 char *ret; 50 51 if (!string) 52 return NULL; 53 while (*string) { 54 if (!isspace(*string)) 55 break; 56 string++; 57 } 58 ret = string; 59 60 string = ret + strlen(ret) - 1; 61 while (string > ret) { 62 if (!isspace(*string)) 63 break; 64 string--; 65 } 66 string[1] = 0; 67 68 return ret; 69} 70 71static inline int has_text(const char *text) 72{ 73 if (!text) 74 return 0; 75 76 while (*text) { 77 if (!isspace(*text)) 78 return 1; 79 text++; 80 } 81 82 return 0; 83} 84 85#endif