20411342384714f47160fedd6ebedaed0f2ad3fd
[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
35 #include <X11/Xfuncproto.h>
36
37 extern void *
38 recalloc(void *ptr, size_t old_size, size_t new_size);
39
40 /*
41  * We sometimes malloc strings and then expose them as const char*'s. This
42  * macro is used when we free these strings in order to avoid -Wcast-qual
43  * errors.
44  */
45 #define UNCONSTIFY(const_ptr) ((void *)(uintptr_t)(const_ptr))
46
47 #define uTypedAlloc(t)              malloc(sizeof(t))
48 #define uTypedCalloc(n, t)          calloc((n), sizeof(t))
49 #define uTypedRealloc(pO, n, t)     realloc((pO), (n) * sizeof(t))
50 #define uTypedRecalloc(pO, o, n, t) recalloc((pO), (o) * sizeof(t), (n) * sizeof(t))
51
52 #define uDupString(s)          ((s) ? strdup(s) : NULL)
53 #define uStringText(s)         ((s) == NULL ? "<NullString>" : (s))
54 #define uStrCasePrefix(s1, s2) (strncasecmp((s1), (s2), strlen(s1)) == 0)
55
56 /***====================================================================***/
57
58 extern bool
59 uSetErrorFile(char *name);
60
61 #define INFO                    uInformation
62
63 extern _X_ATTRIBUTE_PRINTF(1, 2) void
64 uInformation(const char *s, ...);
65
66 #define ACTION                  uAction
67
68 extern _X_ATTRIBUTE_PRINTF(1, 2) void
69 uAction(const char *s, ...);
70
71 #define WARN                    uWarning
72
73 extern _X_ATTRIBUTE_PRINTF(1, 2) void
74 uWarning(const char *s, ...);
75
76 #define ERROR                   uError
77
78 extern _X_ATTRIBUTE_PRINTF(1, 2) void
79 uError(const char *s, ...);
80
81 #define FATAL                   uFatalError
82
83 extern _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN void
84 uFatalError(const char *s, ...);
85
86 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
87 #define WSGO                    uInternalError
88
89 extern _X_ATTRIBUTE_PRINTF(1, 2) void
90 uInternalError(const char *s, ...);
91
92 #endif /* UTILS_H */