Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 */
0002 /*
0003  * Copyright (C) 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
0004  *
0005  */
0006 #ifndef __UTIL_H
0007 #define __UTIL_H
0008 
0009 #include <ctype.h>
0010 
0011 /* Can be overridden */
0012 void warning(const char *fmt, ...);
0013 void pr_stat(const char *fmt, ...);
0014 void vpr_stat(const char *fmt, va_list ap);
0015 
0016 /* Always available */
0017 void __warning(const char *fmt, ...);
0018 void __pr_stat(const char *fmt, ...);
0019 
0020 void __vwarning(const char *fmt, ...);
0021 void __vpr_stat(const char *fmt, ...);
0022 
0023 #define min(x, y) ({                \
0024     typeof(x) _min1 = (x);          \
0025     typeof(y) _min2 = (y);          \
0026     (void) (&_min1 == &_min2);      \
0027     _min1 < _min2 ? _min1 : _min2; })
0028 
0029 static inline char *strim(char *string)
0030 {
0031     char *ret;
0032 
0033     if (!string)
0034         return NULL;
0035     while (*string) {
0036         if (!isspace(*string))
0037             break;
0038         string++;
0039     }
0040     ret = string;
0041 
0042     string = ret + strlen(ret) - 1;
0043     while (string > ret) {
0044         if (!isspace(*string))
0045             break;
0046         string--;
0047     }
0048     string[1] = 0;
0049 
0050     return ret;
0051 }
0052 
0053 static inline int has_text(const char *text)
0054 {
0055     if (!text)
0056         return 0;
0057 
0058     while (*text) {
0059         if (!isspace(*text))
0060             return 1;
0061         text++;
0062     }
0063 
0064     return 0;
0065 }
0066 
0067 #endif