1/*
2 *
3Copyright 1989, 1991, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24 *
25 */
26
27/* Definitions to make function prototypes manageable */
28
29#ifndef _XFUNCPROTO_H_
30#define _XFUNCPROTO_H_
31
32#ifndef NeedFunctionPrototypes
33#define NeedFunctionPrototypes 1
34#endif /* NeedFunctionPrototypes */
35
36#ifndef NeedVarargsPrototypes
37#define NeedVarargsPrototypes 1
38#endif /* NeedVarargsPrototypes */
39
40#if NeedFunctionPrototypes
41
42#ifndef NeedNestedPrototypes
43#define NeedNestedPrototypes 1
44#endif /* NeedNestedPrototypes */
45
46#ifndef _Xconst
47#define _Xconst const
48#endif /* _Xconst */
49
50/* Function prototype configuration (see configure for more info) */
51#if !defined(NARROWPROTO) && \
52 (defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__))
53#define NARROWPROTO
54#endif
55#ifndef FUNCPROTO
56#define FUNCPROTO 15
57#endif
58
59#ifndef NeedWidePrototypes
60#ifdef NARROWPROTO
61#define NeedWidePrototypes 0
62#else
63#define NeedWidePrototypes 1 /* default to make interropt. easier */
64#endif
65#endif /* NeedWidePrototypes */
66
67#endif /* NeedFunctionPrototypes */
68
69#ifndef _XFUNCPROTOBEGIN
70#if defined(__cplusplus) || defined(c_plusplus) /* for C++ V2.0 */
71#define _XFUNCPROTOBEGIN extern "C" { /* do not leave open across includes */
72#define _XFUNCPROTOEND }
73#else
74#define _XFUNCPROTOBEGIN
75#define _XFUNCPROTOEND
76#endif
77#endif /* _XFUNCPROTOBEGIN */
78
79/* http://clang.llvm.org/docs/LanguageExtensions.html#has-attribute */
80#ifndef __has_attribute
81# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
82#endif
83#ifndef __has_feature
84# define __has_feature(x) 0 /* Compatibility with non-clang compilers. */
85#endif
86#ifndef __has_extension
87# define __has_extension(x) 0 /* Compatibility with non-clang compilers. */
88#endif
89
90/* Added in X11R6.9, so available in any version of modular xproto */
91#if __has_attribute(__sentinel__) || (defined(__GNUC__) && (__GNUC__ >= 4))
92# define _X_SENTINEL(x) __attribute__ ((__sentinel__(x)))
93#else
94# define _X_SENTINEL(x)
95#endif /* GNUC >= 4 */
96
97/* Added in X11R6.9, so available in any version of modular xproto */
98#if (__has_attribute(visibility) || (defined(__GNUC__) && (__GNUC__ >= 4))) \
99 && !defined(__CYGWIN__) && !defined(__MINGW32__)
100# define _X_EXPORT __attribute__((visibility("default")))
101# define _X_HIDDEN __attribute__((visibility("hidden")))
102# define _X_INTERNAL __attribute__((visibility("internal")))
103#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
104# define _X_EXPORT __global
105# define _X_HIDDEN __hidden
106# define _X_INTERNAL __hidden
107#else /* not gcc >= 4 and not Sun Studio >= 8 */
108# define _X_EXPORT
109# define _X_HIDDEN
110# define _X_INTERNAL
111#endif /* GNUC >= 4 */
112
113/* Branch prediction hints for individual conditionals */
114/* requires xproto >= 7.0.9 */
115#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
116# define _X_LIKELY(x) __builtin_expect(!!(x), 1)
117# define _X_UNLIKELY(x) __builtin_expect(!!(x), 0)
118#else /* not gcc >= 3.3 */
119# define _X_LIKELY(x) (x)
120# define _X_UNLIKELY(x) (x)
121#endif
122
123/* Bulk branch prediction hints via marking error path functions as "cold" */
124/* requires xproto >= 7.0.25 */
125#if __has_attribute(__cold__) || \
126 (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) /* 4.3+ */
127# define _X_COLD __attribute__((__cold__))
128#else
129# define _X_COLD /* nothing */
130#endif
131
132/* Added in X11R6.9, so available in any version of modular xproto */
133#if __has_attribute(deprecated) \
134 || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 301)) \
135 || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5130))
136# define _X_DEPRECATED __attribute__((deprecated))
137#else /* not gcc >= 3.1 */
138# define _X_DEPRECATED
139#endif
140
141/* requires xproto >= 7.0.30 */
142#if __has_extension(attribute_deprecated_with_message) || \
143 (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
144# define _X_DEPRECATED_MSG(_msg) __attribute__((deprecated(_msg)))
145#else
146# define _X_DEPRECATED_MSG(_msg) _X_DEPRECATED
147#endif
148
149/* requires xproto >= 7.0.17 */
150#if __has_attribute(noreturn) \
151 || (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)) \
152 || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
153# define _X_NORETURN __attribute((noreturn))
154#else
155# define _X_NORETURN
156#endif /* GNUC */
157
158/* Added in X11R6.9, so available in any version of modular xproto */
159#if __has_attribute(__format__) \
160 || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203)
161# define _X_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
162#else /* not gcc >= 2.3 */
163# define _X_ATTRIBUTE_PRINTF(x,y)
164#endif
165
166/* requires xproto >= 7.0.22 - since this uses either gcc or C99 variable
167 argument macros, must be only used inside #ifdef _X_NONNULL guards, as
168 many legacy X clients are compiled in C89 mode still. */
169#if __has_attribute(nonnull) \
170 && defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
171#define _X_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
172#elif __has_attribute(nonnull) \
173 || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 303)
174#define _X_NONNULL(args...) __attribute__((nonnull(args)))
175#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */
176#define _X_NONNULL(...) /* */
177#endif
178
179/* requires xproto >= 7.0.22 */
180#if __has_attribute(__unused__) \
181 || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 205)
182#define _X_UNUSED __attribute__((__unused__))
183#else
184#define _X_UNUSED /* */
185#endif
186
187/* C99 keyword "inline" or equivalent extensions in pre-C99 compilers */
188/* requires xproto >= 7.0.9
189 (introduced in 7.0.8 but didn't support all compilers until 7.0.9) */
190#if defined(inline) /* assume autoconf set it correctly */ || \
191 (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L)) /* C99 */ || \
192 (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550))
193# define _X_INLINE inline
194#elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
195# define _X_INLINE __inline__
196#else
197# define _X_INLINE
198#endif
199
200/* C99 keyword "restrict" or equivalent extensions in pre-C99 compilers */
201/* requires xproto >= 7.0.21 */
202#ifndef _X_RESTRICT_KYWD
203# if defined(restrict) /* assume autoconf set it correctly */ || \
204 (defined(__STDC_VERSION__) && (__STDC_VERSION__ - 0 >= 199901L) /* C99 */ \
205 && !defined(__cplusplus)) /* Workaround g++ issue on Solaris */
206# define _X_RESTRICT_KYWD restrict
207# elif defined(__GNUC__) && !defined(__STRICT_ANSI__) /* gcc w/C89+extensions */
208# define _X_RESTRICT_KYWD __restrict__
209# else
210# define _X_RESTRICT_KYWD
211# endif
212#endif
213
214/* requires xproto >= 7.0.30 */
215#if __has_attribute(no_sanitize_thread)
216# define _X_NOTSAN __attribute__((no_sanitize_thread))
217#else
218# define _X_NOTSAN
219#endif
220
221/* Mark a char array/pointer as not containing a NUL-terminated string */
222/* requires xproto >= 7.0.33 */
223#if __has_attribute(nonstring)
224# define _X_NONSTRING __attribute__((nonstring))
225#else
226# define _X_NONSTRING
227#endif
228
229#endif /* _XFUNCPROTO_H_ */
230