2 * Copyright © 2012 Ran Benita <ran234@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
31 * We sometimes malloc strings and then expose them as const char*'s. This
32 * macro is used when we free these strings in order to avoid -Wcast-qual
35 #define UNCONSTIFY(const_ptr) ((void *) (uintptr_t) (const_ptr))
38 streq(const char *s1, const char *s2)
40 return strcmp(s1, s2) == 0;
44 streq_not_null(const char *s1, const char *s2)
52 istreq(const char *s1, const char *s2)
54 return strcasecmp(s1, s2) == 0;
58 istreq_prefix(const char *s1, const char *s2)
60 return strncasecmp(s1, s2, strlen(s1)) == 0;
64 strdup_safe(const char *s)
66 return s ? strdup(s) : NULL;
70 isempty(const char *s)
72 return s == NULL || s[0] == '\0';
75 static inline const char *
76 strnull(const char *s)
78 return s ? s : "(null)";
81 #define MIN(a, b) ((a) < (b) ? (a) : (b))
82 #define MAX(a, b) ((a) > (b) ? (a) : (b))
84 /* Compiler Attributes */
86 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__CYGWIN__)
87 # define XKB_EXPORT __attribute__((visibility("default")))
88 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
89 # define XKB_EXPORT __global
90 #else /* not gcc >= 4 and not Sun Studio >= 8 */
94 #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
95 # define ATTR_PRINTF(x,y) __attribute__((__format__(__printf__, x, y)))
96 #else /* not gcc >= 2.3 */
97 # define ATTR_PRINTF(x,y)
100 #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
101 || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
102 # define ATTR_NORETURN __attribute__((__noreturn__))
104 # define ATTR_NORETURN
107 #if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 296)
108 #define ATTR_MALLOC __attribute__((__malloc__))
113 #if defined(__GNUC__) && (__GNUC__ >= 4)
114 # define ATTR_NULL_SENTINEL __attribute__((__sentinel__))
116 # define ATTR_NULL_SENTINEL
117 #endif /* GNUC >= 4 */