utils: remove Xfuncproto.h and use our own macros
[platform/upstream/libxkbcommon.git] / src / utils.h
1 #ifndef UTILS_H
2 #define UTILS_H 1
3
4 /*\
5  *
6  *                          COPYRIGHT 1990
7  *                    DIGITAL EQUIPMENT CORPORATION
8  *                       MAYNARD, MASSACHUSETTS
9  *                        ALL RIGHTS RESERVED.
10  *
11  * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
12  * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
13  * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
14  * FOR ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
15  * WARRANTY.
16  *
17  * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
18  * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
19  * ADDITION TO THAT SET FORTH ABOVE.
20  *
21  * Permission to use, copy, modify, and distribute this software and its
22  * documentation for any purpose and without fee is hereby granted, provided
23  * that the above copyright notice appear in all copies and that both that
24  * copyright notice and this permission notice appear in supporting
25  * documentation, and that the name of Digital Equipment Corporation not be
26  * used in advertising or publicity pertaining to distribution of the
27  * software without specific, written prior permission.
28  \*/
29
30 /***====================================================================***/
31
32 #include <stdbool.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 /*
37  * We sometimes malloc strings and then expose them as const char*'s. This
38  * macro is used when we free these strings in order to avoid -Wcast-qual
39  * errors.
40  */
41 #define UNCONSTIFY(const_ptr)  ((void *) (uintptr_t) (const_ptr))
42
43 #define uDupString(s)          ((s) ? strdup(s) : NULL)
44 #define uStringText(s)         ((s) == NULL ? "<NullString>" : (s))
45 #define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
46
47 /* Compiler Attributes */
48
49 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__CYGWIN__)
50 # define XKB_EXPORT      __attribute__((visibility("default")))
51 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
52 # define XKB_EXPORT      __global
53 #else /* not gcc >= 4 and not Sun Studio >= 8 */
54 # define XKB_EXPORT
55 #endif
56
57 #if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
58 # define ATTR_PRINTF(x,y) __attribute__((__format__(__printf__, x, y)))
59 #else /* not gcc >= 2.3 */
60 # define ATTR_PRINTF(x,y)
61 #endif
62
63 #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
64     || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
65 # define ATTR_NORETURN __attribute__((__noreturn__))
66 #else
67 # define ATTR_NORETURN
68 #endif /* GNUC  */
69
70 extern bool
71 uSetErrorFile(char *name);
72
73 #define INFO uInformation
74
75 ATTR_PRINTF(1, 2) void
76 uInformation(const char *s, ...);
77
78 #define ACTION uAction
79
80 ATTR_PRINTF(1, 2) void
81 uAction(const char *s, ...);
82
83 #define WARN uWarning
84
85 ATTR_PRINTF(1, 2) void
86 uWarning(const char *s, ...);
87
88 #define ERROR uError
89
90 ATTR_PRINTF(1, 2) void
91 uError(const char *s, ...);
92
93 #define FATAL uFatalError
94
95 ATTR_PRINTF(1, 2) ATTR_NORETURN void
96 uFatalError(const char *s, ...);
97
98 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
99 #define WSGO uInternalError
100
101 ATTR_PRINTF(1, 2) void
102 uInternalError(const char *s, ...);
103
104 #endif /* UTILS_H */