1 /* $OpenBSD: cdefs.h,v 1.25 2007/06/26 10:30:05 tom Exp $ */
2 /* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */
3
4 /*
5 * Copyright (c) 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Berkeley Software Design, Inc.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)cdefs.h 8.7 (Berkeley) 1/21/94
36 */
37
38 #ifndef _SYS_CDEFS_H_
39 #define _SYS_CDEFS_H_
40
41 #include <machine/cdefs.h>
42
43 #if defined(__cplusplus)
44 #define __BEGIN_DECLS extern "C" {
45 #define __END_DECLS }
46 #else
47 #define __BEGIN_DECLS
48 #define __END_DECLS
49 #endif
50
51 /*
52 * Macro to test if we're using a specific version of gcc or later.
53 */
54 #ifdef __GNUC__
55 #define __GNUC_PREREQ__(ma, mi) \
56 ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
57 #else
58 #define __GNUC_PREREQ__(ma, mi) 0
59 #endif
60
61 /*
62 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
63 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
64 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
65 * in between its arguments. __CONCAT can also concatenate double-quoted
66 * strings produced by the __STRING macro, but this only works with ANSI C.
67 */
68 #if defined(__STDC__) || defined(__cplusplus)
69 #define __P(protos) protos /* full-blown ANSI C */
70 #define __CONCAT(x,y) x ## y
71 #define __STRING(x) #x
72
73 #define __const const /* define reserved names to standard */
74 #define __signed signed
75 #define __volatile volatile
76 #if defined(__cplusplus)
77 #define __inline inline /* convert to C++ keyword */
78 #else
79 #if !defined(__GNUC__) && !defined(lint)
80 #define __inline /* delete GCC keyword */
81 #endif /* !__GNUC__ && !lint */
82 #endif /* !__cplusplus */
83
84 #else /* !(__STDC__ || __cplusplus) */
85 #define __P(protos) () /* traditional C preprocessor */
86 #define __CONCAT(x,y) x/**/y
87 #define __STRING(x) "x"
88
89 #if !defined(__GNUC__) && !defined(lint)
90 #define __const /* delete pseudo-ANSI C keywords */
91 #define __inline
92 #define __signed
93 #define __volatile
94 #endif /* !__GNUC__ && !lint */
95
96 /*
97 * In non-ANSI C environments, new programs will want ANSI-only C keywords
98 * deleted from the program and old programs will want them left alone.
99 * Programs using the ANSI C keywords const, inline etc. as normal
100 * identifiers should define -DNO_ANSI_KEYWORDS.
101 */
102 #ifndef NO_ANSI_KEYWORDS
103 #define const __const /* convert ANSI C keywords */
104 #define inline __inline
105 #define signed __signed
106 #define volatile __volatile
107 #endif /* !NO_ANSI_KEYWORDS */
108 #endif /* !(__STDC__ || __cplusplus) */
109
110 /*
111 * GCC1 and some versions of GCC2 declare dead (non-returning) and
112 * pure (no side effects) functions using "volatile" and "const";
113 * unfortunately, these then cause warnings under "-ansi -pedantic".
114 * GCC >= 2.5 uses the __attribute__((attrs)) style. All of these
115 * work for GNU C++ (modulo a slight glitch in the C++ grammar in
116 * the distribution version of 2.5.5).
117 */
118
119 #if !__GNUC_PREREQ__(2, 5)
120 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
121 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
122 #define __dead __volatile
123 #define __pure __const
124 #elif defined(lint)
125 #define __dead /* NORETURN */
126 #endif
127 #elif !defined(__STRICT_ANSI__)
128 #define __dead __attribute__((__noreturn__))
129 #define __pure __attribute__((__const__))
130 #endif
131
132 /*
133 * GNU C version 2.96 adds explicit branch prediction so that
134 * the CPU back-end can hint the processor and also so that
135 * code blocks can be reordered such that the predicted path
136 * sees a more linear flow, thus improving cache behavior, etc.
137 *
138 * The following two macros provide us with a way to utilize this
139 * compiler feature. Use __predict_true() if you expect the expression
140 * to evaluate to true, and __predict_false() if you expect the
141 * expression to evaluate to false.
142 *
143 * A few notes about usage:
144 *
145 * * Generally, __predict_false() error condition checks (unless
146 * you have some _strong_ reason to do otherwise, in which case
147 * document it), and/or __predict_true() `no-error' condition
148 * checks, assuming you want to optimize for the no-error case.
149 *
150 * * Other than that, if you don't know the likelihood of a test
151 * succeeding from empirical or other `hard' evidence, don't
152 * make predictions.
153 *
154 * * These are meant to be used in places that are run `a lot'.
155 * It is wasteful to make predictions in code that is run
156 * seldomly (e.g. at subsystem initialization time) as the
157 * basic block reordering that this affects can often generate
158 * larger code.
159 */
160 #if __GNUC_PREREQ__(2, 96)
161 #define __predict_true(exp) __builtin_expect(((exp) != 0), 1)
162 #define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
163 #else
164 #define __predict_true(exp) ((exp) != 0)
165 #define __predict_false(exp) ((exp) != 0)
166 #endif
167
168 /* Delete pseudo-keywords wherever they are not available or needed. */
169 #ifndef __dead
170 #define __dead
171 #define __pure
172 #endif
173
174 #if __GNUC_PREREQ__(2, 7)
175 #define __packed __attribute__((__packed__))
176 #elif defined(lint)
177 #define __packed
178 #endif
179
180 #if !__GNUC_PREREQ__(2, 8)
181 #define __extension__
182 #endif
183
184 #if __GNUC_PREREQ__(2, 8)
185 #define __statement(x) __extension__(x)
186 #elif defined(lint)
187 #define __statement(x) (0)
188 #else
189 #define __statement(x) (x)
190 #endif
191
192 #if __GNUC_PREREQ__(3, 0)
193 #define __malloc __attribute__((__malloc__))
194 #else
195 #define __malloc
196 #endif
197
198 /*
199 * "The nice thing about standards is that there are so many to choose from."
200 * There are a number of "feature test macros" specified by (different)
201 * standards that determine which interfaces and types the header files
202 * should expose.
203 *
204 * Because of inconsistencies in these macros, we define our own
205 * set in the private name space that end in _VISIBLE. These are
206 * always defined and so headers can test their values easily.
207 * Things can get tricky when multiple feature macros are defined.
208 * We try to take the union of all the features requested.
209 *
210 * The following macros are guaranteed to have a value after cdefs.h
211 * has been included:
212 * __POSIX_VISIBLE
213 * __XPG_VISIBLE
214 * __ISO_C_VISIBLE
215 * __BSD_VISIBLE
216 */
217
218 /*
219 * X/Open Portability Guides and Single Unix Specifications.
220 * _XOPEN_SOURCE XPG3
221 * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
222 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
223 * _XOPEN_SOURCE == 500 XPG5
224 * _XOPEN_SOURCE == 520 XPG5v2
225 * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI
226 *
227 * The XPG spec implies a specific value for _POSIX_C_SOURCE.
228 */
229 #ifdef _XOPEN_SOURCE
230 # if (_XOPEN_SOURCE - 0 >= 600)
231 # define __XPG_VISIBLE 600
232 # undef _POSIX_C_SOURCE
233 # define _POSIX_C_SOURCE 200112L
234 # elif (_XOPEN_SOURCE - 0 >= 520)
235 # define __XPG_VISIBLE 520
236 # undef _POSIX_C_SOURCE
237 # define _POSIX_C_SOURCE 199506L
238 # elif (_XOPEN_SOURCE - 0 >= 500)
239 # define __XPG_VISIBLE 500
240 # undef _POSIX_C_SOURCE
241 # define _POSIX_C_SOURCE 199506L
242 # elif (_XOPEN_SOURCE_EXTENDED - 0 == 1)
243 # define __XPG_VISIBLE 420
244 # elif (_XOPEN_VERSION - 0 >= 4)
245 # define __XPG_VISIBLE 400
246 # else
247 # define __XPG_VISIBLE 300
248 # endif
249 #endif
250
251 /*
252 * POSIX macros, these checks must follow the XOPEN ones above.
253 *
254 * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE)
255 * _POSIX_C_SOURCE == 1 1003.1-1990
256 * _POSIX_C_SOURCE == 2 1003.2-1992
257 * _POSIX_C_SOURCE == 199309L 1003.1b-1993
258 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
259 * and the omnibus ISO/IEC 9945-1:1996
260 * _POSIX_C_SOURCE == 200112L 1003.1-2001
261 *
262 * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though
263 * this may be overridden by the _ISOC99_SOURCE macro later.
264 */
265 #ifdef _POSIX_C_SOURCE
266 # if (_POSIX_C_SOURCE - 0 >= 200112)
267 # define __POSIX_VISIBLE 200112
268 # define __ISO_C_VISIBLE 1999
269 # elif (_POSIX_C_SOURCE - 0 >= 199506)
270 # define __POSIX_VISIBLE 199506
271 # define __ISO_C_VISIBLE 1990
272 # elif (_POSIX_C_SOURCE - 0 >= 199309)
273 # define __POSIX_VISIBLE 199309
274 # define __ISO_C_VISIBLE 1990
275 # elif (_POSIX_C_SOURCE - 0 >= 2)
276 # define __POSIX_VISIBLE 199209
277 # define __ISO_C_VISIBLE 1990
278 # else
279 # define __POSIX_VISIBLE 199009
280 # define __ISO_C_VISIBLE 1990
281 # endif
282 #elif defined(_POSIX_SOURCE)
283 # define __POSIX_VISIBLE 198808
284 # define __ISO_C_VISIBLE 0
285 #endif
286
287 /*
288 * _ANSI_SOURCE means to expose ANSI C89 interfaces only.
289 * If the user defines it in addition to one of the POSIX or XOPEN
290 * macros, assume the POSIX/XOPEN macro(s) should take precedence.
291 */
292 #if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \
293 !defined(__XPG_VISIBLE)
294 # define __POSIX_VISIBLE 0
295 # define __XPG_VISIBLE 0
296 # define __ISO_C_VISIBLE 1990
297 #endif
298
299 /*
300 * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since
301 * they are non-exclusive.
302 */
303 #if defined(_ISOC99_SOURCE) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
304 # undef __ISO_C_VISIBLE
305 # define __ISO_C_VISIBLE 1999
306 #endif
307
308 /*
309 * Finally deal with BSD-specific interfaces that are not covered
310 * by any standards. We expose these when one of the POSIX or XPG
311 * macros is defined or if the user explicitly asks for them.
312 */
313 #if !defined(_BSD_SOURCE) && \
314 (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
315 # define __BSD_VISIBLE 0
316 #endif
317
318 /*
319 * Default values.
320 */
321 #ifndef __XPG_VISIBLE
322 # define __XPG_VISIBLE 600
323 #endif
324 #ifndef __POSIX_VISIBLE
325 # define __POSIX_VISIBLE 200112
326 #endif
327 #ifndef __ISO_C_VISIBLE
328 # define __ISO_C_VISIBLE 1999
329 #endif
330 #ifndef __BSD_VISIBLE
331 # define __BSD_VISIBLE 1
332 #endif
333
334 #endif /* !_SYS_CDEFS_H_ */