]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/cdefs.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / sys / cdefs.h
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/* Copyright 1995 NeXT Computer, Inc. All rights reserved. */
31/*
32 * Copyright (c) 1991, 1993
33 * The Regents of the University of California. All rights reserved.
34 *
35 * This code is derived from software contributed to Berkeley by
36 * Berkeley Software Design, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
67 */
68
69#ifndef _CDEFS_H_
70#define _CDEFS_H_
71
72#if defined(__cplusplus)
73#define __BEGIN_DECLS extern "C" {
74#define __END_DECLS }
75#else
76#define __BEGIN_DECLS
77#define __END_DECLS
78#endif
79
80/*
81 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
82 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
83 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
84 * in between its arguments. __CONCAT can also concatenate double-quoted
85 * strings produced by the __STRING macro, but this only works with ANSI C.
86 */
87#if defined(__STDC__) || defined(__cplusplus)
88#define __P(protos) protos /* full-blown ANSI C */
89#define __CONCAT(x,y) x ## y
90#define __STRING(x) #x
91
92#define __const const /* define reserved names to standard */
93#define __signed signed
94#define __volatile volatile
95#if defined(__cplusplus)
96#define __inline inline /* convert to C++ keyword */
97#else
98#ifndef __GNUC__
99#define __inline /* delete GCC keyword */
100#endif /* !__GNUC__ */
101#endif /* !__cplusplus */
102
103#else /* !(__STDC__ || __cplusplus) */
104#define __P(protos) () /* traditional C preprocessor */
105#define __CONCAT(x,y) x/**/y
106#define __STRING(x) "x"
107
108#ifndef __GNUC__
109#define __const /* delete pseudo-ANSI C keywords */
110#define __inline
111#define __signed
112#define __volatile
113#endif /* !__GNUC__ */
114
115/*
116 * In non-ANSI C environments, new programs will want ANSI-only C keywords
117 * deleted from the program and old programs will want them left alone.
118 * When using a compiler other than gcc, programs using the ANSI C keywords
119 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
120 * When using "gcc -traditional", we assume that this is the intent; if
121 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
122 */
123#ifndef NO_ANSI_KEYWORDS
124#define const __const /* convert ANSI C keywords */
125#define inline __inline
126#define signed __signed
127#define volatile __volatile
128#endif /* !NO_ANSI_KEYWORDS */
129#endif /* !(__STDC__ || __cplusplus) */
130
131/*
132 * GCC1 and some versions of GCC2 declare dead (non-returning) and
133 * pure (no side effects) functions using "volatile" and "const";
134 * unfortunately, these then cause warnings under "-ansi -pedantic".
135 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
136 * these work for GNU C++ (modulo a slight glitch in the C++ grammar
137 * in the distribution version of 2.5.5).
138 */
0b4e3aa0
A
139#if defined(__MWERKS__) && (__MWERKS__ > 0x2400)
140 /* newer Metrowerks compilers support __attribute__() */
55e303ae
A
141#elif __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 5
142#define __dead2 __attribute__((__noreturn__))
143#define __pure2 __attribute__((__const__))
144#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
145#define __unused /* no attribute */
146#else
147#define __unused __attribute__((__unused__))
148#endif
149#else
1c79356b
A
150#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
151#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
55e303ae 152/* __dead and __pure are depreciated. Use __dead2 and __pure2 instead */
1c79356b
A
153#define __dead __volatile
154#define __pure __const
155#endif
156#endif
157
158/* Delete pseudo-keywords wherever they are not available or needed. */
159#ifndef __dead
160#define __dead
161#define __pure
162#endif
55e303ae
A
163#ifndef __dead2
164#define __dead2
165#define __pure2
166#define __unused
167#endif
1c79356b 168
91447636
A
169/*
170 * GCC 2.95 provides `__restrict' as an extension to C90 to support the
171 * C99-specific `restrict' type qualifier. We happen to use `__restrict' as
172 * a way to define the `restrict' type qualifier without disturbing older
173 * software that is unaware of C99 keywords.
174 */
175#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
176#if __STDC_VERSION__ < 199901
177#define __restrict
178#else
179#define __restrict restrict
180#endif
181#endif
182
183/*
184 * Compiler-dependent macros to declare that functions take printf-like
185 * or scanf-like arguments. They are null except for versions of gcc
186 * that are known to support the features properly. Functions declared
187 * with these attributes will cause compilation warnings if there is a
188 * mismatch between the format string and subsequent function parameter
189 * types.
190 */
191#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
192#define __printflike(fmtarg, firstvararg) \
193 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
194#define __scanflike(fmtarg, firstvararg) \
195 __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
196#else
197#define __printflike(fmtarg, firstvararg)
198#define __scanflike(fmtarg, firstvararg)
199#endif
200
55e303ae 201#define __IDSTRING(name,string) static const char name[] __unused = string
1c79356b
A
202
203#ifndef __COPYRIGHT
204#define __COPYRIGHT(s) __IDSTRING(copyright,s)
205#endif
206
207#ifndef __RCSID
208#define __RCSID(s) __IDSTRING(rcsid,s)
209#endif
210
211#ifndef __SCCSID
212#define __SCCSID(s) __IDSTRING(sccsid,s)
213#endif
214
215#ifndef __PROJECT_VERSION
216#define __PROJECT_VERSION(s) __IDSTRING(project_version,s)
217#endif
218
91447636
A
219/*
220 * The __DARWIN_ALIAS macros is used to do symbol renaming,
221 * they allow old code to use the old symbol thus maintiang binary
222 * compatability while new code can use a new improved version of the
223 * same function.
224 *
225 * By default newly complied code will actually get the same symbols
226 * that the old code did. Defining any of _APPLE_C_SOURCE, _XOPEN_SOURCE,
227 * or _POSIX_C_SOURCE will give you the new symbols. Defining _XOPEN_SOURCE
228 * or _POSIX_C_SOURCE also restricts the avilable symbols to a subset of
229 * Apple's APIs.
230 *
231 * __DARWIN_ALIAS is used by itself if the function signature has not
232 * changed, it is used along with a #ifdef check for __DARWIN_UNIX03
233 * if the signature has changed. Because the __LP64__ enviroment
234 * only supports UNIX03 sementics it causes __DARWIN_UNIX03 to be
235 * defined, but causes __DARWIN_ALIAS to do no symbol mangling.
236 */
237
238#if !defined(__DARWIN_UNIX03)
239#if defined(_APPLE_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE) || defined(__LP64__)
240#if defined(_NONSTD_SOURCE)
241#error "Can't define both _NONSTD_SOURCE and any of _APPLE_C_SOURCE, _XOPEN_SOURCE, _POSIX_C_SOURCE, or __LP64__"
242#endif /* _NONSTD_SOURCE */
243#define __DARWIN_UNIX03 1
244#elif defined(_NONSTD_SOURCE)
245#define __DARWIN_UNIX03 0
246#else /* default */
247#define __DARWIN_UNIX03 0
248#endif /* _APPLE_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */
249#endif /* !__DARWIN_UNIX03 */
250
251#if __DARWIN_UNIX03 && !defined(__LP64__)
252#define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) "$UNIX2003")
253#else
254#define __DARWIN_ALIAS(sym)
255#endif
256
257
258/*
259 * POSIX.1 requires that the macros we test be defined before any standard
260 * header file is included. This permits us to convert values for feature
261 * testing, as necessary, using only _POSIX_C_SOURCE.
262 *
263 * Here's a quick run-down of the versions:
264 * defined(_POSIX_SOURCE) 1003.1-1988
265 * _POSIX_C_SOURCE == 1L 1003.1-1990
266 * _POSIX_C_SOURCE == 2L 1003.2-1992 C Language Binding Option
267 * _POSIX_C_SOURCE == 199309L 1003.1b-1993
268 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
269 * and the omnibus ISO/IEC 9945-1: 1996
270 * _POSIX_C_SOURCE == 200112L 1003.1-2001
271 *
272 * In addition, the X/Open Portability Guide, which is now the Single UNIX
273 * Specification, defines a feature-test macro which indicates the version of
274 * that specification, and which subsumes _POSIX_C_SOURCE.
275 */
276
277/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */
278#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L
279#undef _POSIX_C_SOURCE
280#define _POSIX_C_SOURCE 199009L
281#endif
282
283/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */
284#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L
285#undef _POSIX_C_SOURCE
286#define _POSIX_C_SOURCE 199209L
287#endif
288
289/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
290#ifdef _XOPEN_SOURCE
291#if _XOPEN_SOURCE - 0L >= 600L
292#undef _POSIX_C_SOURCE
293#define _POSIX_C_SOURCE 200112L
294#elif _XOPEN_SOURCE - 0L >= 500L
295#undef _POSIX_C_SOURCE
296#define _POSIX_C_SOURCE 199506L
297#endif
298#endif
299
300/*
301 * Deal with all versions of POSIX. The ordering relative to the tests above is
302 * important.
303 */
304#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
305#define _POSIX_C_SOURCE 198808L
306#endif
307
308/*
309 * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and
310 * c99 still want long longs. While not perfect, we allow long longs for
311 * g++.
312 */
313#define __DARWIN_NO_LONG_LONG (defined(__STRICT_ANSI__) \
314 && (__STDC_VERSION__-0 < 199901L) \
315 && !defined(__GNUG__))
316
317/*
318 * Long double compatibility macro allow selecting variant symbols based
319 * on the old (compatible) 64-bit long doubles, or the new 128-bit
320 * long doubles. This applies only to ppc; i386 already has long double
321 * support, while ppc64 doesn't have any backwards history.
322 */
323#if defined(__ppc__)
324# if defined(__LDBL_MANT_DIG__) && defined(__DBL_MANT_DIG__) && \
325 __LDBL_MANT_DIG__ > __DBL_MANT_DIG__
326# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1040
327# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBLStub")
328# else
329# define __DARWIN_LDBL_COMPAT(x) __asm("_" __STRING(x) "$LDBL128")
330# endif
331# define __DARWIN_LDBL_COMPAT2(x) __asm("_" __STRING(x) "$LDBL128")
332# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
333# else
334# define __DARWIN_LDBL_COMPAT(x) /* nothing */
335# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
336# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 1
337# endif
5d5c5d0d 338#elif defined(__i386__) || defined(__ppc64__) || defined(__x86_64__)
91447636
A
339# define __DARWIN_LDBL_COMPAT(x) /* nothing */
340# define __DARWIN_LDBL_COMPAT2(x) /* nothing */
341# define __DARWIN_LONG_DOUBLE_IS_DOUBLE 0
342#else
343# error Unknown architecture
344#endif
345
1c79356b 346#endif /* !_CDEFS_H_ */