cdefs.h revision 211335
1139825Simp/*-
21541Srgrimes * Copyright (c) 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Berkeley Software Design, Inc.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 4. Neither the name of the University nor the names of its contributors
171541Srgrimes *    may be used to endorse or promote products derived from this software
181541Srgrimes *    without specific prior written permission.
191541Srgrimes *
201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301541Srgrimes * SUCH DAMAGE.
311541Srgrimes *
3214495Shsu *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
3350477Speter * $FreeBSD: head/sys/sys/cdefs.h 211335 2010-08-15 14:38:01Z kib $
341541Srgrimes */
351541Srgrimes
362165Spaul#ifndef	_SYS_CDEFS_H_
372165Spaul#define	_SYS_CDEFS_H_
381541Srgrimes
391541Srgrimes#if defined(__cplusplus)
401541Srgrimes#define	__BEGIN_DECLS	extern "C" {
4136449Sdt#define	__END_DECLS	}
421541Srgrimes#else
431541Srgrimes#define	__BEGIN_DECLS
441541Srgrimes#define	__END_DECLS
451541Srgrimes#endif
461541Srgrimes
471541Srgrimes/*
48143063Sjoerg * This code has been put in place to help reduce the addition of
49143063Sjoerg * compiler specific defines in FreeBSD code.  It helps to aid in
50143063Sjoerg * having a compiler-agnostic source tree.
51143063Sjoerg */
52143063Sjoerg
53143063Sjoerg#if defined(__GNUC__) || defined(__INTEL_COMPILER)
54143063Sjoerg
55143063Sjoerg#if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
56143063Sjoerg#define __GNUCLIKE_ASM 3
57143063Sjoerg#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
58143063Sjoerg#else
59143063Sjoerg#define __GNUCLIKE_ASM 2
60143063Sjoerg#endif
61143063Sjoerg#define __GNUCLIKE___TYPEOF 1
62143063Sjoerg#define __GNUCLIKE___OFFSETOF 1
63143063Sjoerg#define __GNUCLIKE___SECTION 1
64143063Sjoerg
65143063Sjoerg#define __GNUCLIKE_ATTRIBUTE_MODE_DI 1
66143063Sjoerg
67143063Sjoerg#ifndef __INTEL_COMPILER
68143063Sjoerg# define __GNUCLIKE_CTOR_SECTION_HANDLING 1
69143063Sjoerg#endif
70143063Sjoerg
71143063Sjoerg#define __GNUCLIKE_BUILTIN_CONSTANT_P 1
72143063Sjoerg# if defined(__INTEL_COMPILER) && defined(__cplusplus) \
73143063Sjoerg    && __INTEL_COMPILER < 800
74143063Sjoerg#  undef __GNUCLIKE_BUILTIN_CONSTANT_P
75143063Sjoerg# endif
76143063Sjoerg
77150976Snetchild#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
78143063Sjoerg# define __GNUCLIKE_BUILTIN_VARARGS 1
79150976Snetchild# define __GNUCLIKE_BUILTIN_STDARG 1
80150976Snetchild# define __GNUCLIKE_BUILTIN_VAALIST 1
81143063Sjoerg#endif
82143063Sjoerg
83143063Sjoerg#if defined(__GNUC__)
84143063Sjoerg# define __GNUC_VA_LIST_COMPATIBILITY 1
85143063Sjoerg#endif
86143063Sjoerg
87143063Sjoerg#ifndef __INTEL_COMPILER
88143063Sjoerg# define __GNUCLIKE_BUILTIN_NEXT_ARG 1
89143063Sjoerg# define __GNUCLIKE_MATH_BUILTIN_RELOPS
90143063Sjoerg#endif
91143063Sjoerg
92143063Sjoerg#define __GNUCLIKE_BUILTIN_MEMCPY 1
93143063Sjoerg
94143063Sjoerg/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
95143063Sjoerg#define __CC_SUPPORTS_INLINE 1
96143063Sjoerg#define __CC_SUPPORTS___INLINE 1
97143063Sjoerg#define __CC_SUPPORTS___INLINE__ 1
98143063Sjoerg
99143063Sjoerg#define __CC_SUPPORTS___FUNC__ 1
100143063Sjoerg#define __CC_SUPPORTS_WARNING 1
101143063Sjoerg
102143063Sjoerg#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
103143063Sjoerg
104143063Sjoerg#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
105143063Sjoerg
106143063Sjoerg#endif /* __GNUC__ || __INTEL_COMPILER */
107143063Sjoerg
108143063Sjoerg/*
109120608Smux * Macro to test if we're using a specific version of gcc or later.
110120608Smux */
111126891Strhodes#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
112120608Smux#define	__GNUC_PREREQ__(ma, mi)	\
113120629Smux	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
114120608Smux#else
115120608Smux#define	__GNUC_PREREQ__(ma, mi)	0
116120608Smux#endif
117120608Smux
118120608Smux/*
1191541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
1201541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
12136971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
12236971Sbde * mode -- there must be no spaces between its arguments, and for nested
12336971Sbde * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
12436971Sbde * concatenate double-quoted strings produced by the __STRING macro, but
12536971Sbde * this only works with ANSI C.
12625083Sjdp *
12725083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument
12825083Sjdp * first.  It is only available with ANSI C.
1291541Srgrimes */
1301541Srgrimes#if defined(__STDC__) || defined(__cplusplus)
1311541Srgrimes#define	__P(protos)	protos		/* full-blown ANSI C */
1325012Sbde#define	__CONCAT1(x,y)	x ## y
1335012Sbde#define	__CONCAT(x,y)	__CONCAT1(x,y)
13425083Sjdp#define	__STRING(x)	#x		/* stringify without expanding x */
13525083Sjdp#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
1361541Srgrimes
1371541Srgrimes#define	__const		const		/* define reserved names to standard */
1381541Srgrimes#define	__signed	signed
1391541Srgrimes#define	__volatile	volatile
1401541Srgrimes#if defined(__cplusplus)
1411541Srgrimes#define	__inline	inline		/* convert to C++ keyword */
1421541Srgrimes#else
143143063Sjoerg#if !(defined(__CC_SUPPORTS___INLINE))
1441541Srgrimes#define	__inline			/* delete GCC keyword */
145143063Sjoerg#endif /* ! __CC_SUPPORTS___INLINE */
1461541Srgrimes#endif /* !__cplusplus */
1471541Srgrimes
1481541Srgrimes#else	/* !(__STDC__ || __cplusplus) */
1491541Srgrimes#define	__P(protos)	()		/* traditional C preprocessor */
1501541Srgrimes#define	__CONCAT(x,y)	x/**/y
1511541Srgrimes#define	__STRING(x)	"x"
1521541Srgrimes
153143063Sjoerg#if !defined(__CC_SUPPORTS___INLINE)
1541541Srgrimes#define	__const				/* delete pseudo-ANSI C keywords */
1551541Srgrimes#define	__inline
1561541Srgrimes#define	__signed
1571541Srgrimes#define	__volatile
1581541Srgrimes/*
1591541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords
1601541Srgrimes * deleted from the program and old programs will want them left alone.
1611541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords
1621541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
1631541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if
1641541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
1651541Srgrimes */
1661541Srgrimes#ifndef	NO_ANSI_KEYWORDS
1671541Srgrimes#define	const				/* delete ANSI C keywords */
1681541Srgrimes#define	inline
1691541Srgrimes#define	signed
1701541Srgrimes#define	volatile
1715209Snate#endif	/* !NO_ANSI_KEYWORDS */
172143063Sjoerg#endif	/* !__CC_SUPPORTS___INLINE */
1731541Srgrimes#endif	/* !(__STDC__ || __cplusplus) */
1741541Srgrimes
1751541Srgrimes/*
17638509Sbde * Compiler-dependent macros to help declare dead (non-returning) and
17738509Sbde * pure (no side effects) functions, and unused variables.  They are
17838509Sbde * null except for versions of gcc that are known to support the features
17938509Sbde * properly (old versions of gcc-2 supported the dead and pure features
180103845Speter * in a different (wrong) way).  If we do not provide an implementation
181103845Speter * for a given compiler, let the compile fail if it is told to use
182103845Speter * a feature that we cannot live without.
1831541Srgrimes */
184103845Speter#ifdef lint
18583443Sasmodai#define	__dead2
18683443Sasmodai#define	__pure2
18783443Sasmodai#define	__unused
188103834Speter#define	__packed
189103836Speter#define	__aligned(x)
190103841Speter#define	__section(x)
191103845Speter#else
192126891Strhodes#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
193103845Speter#define	__dead2
194103845Speter#define	__pure2
195103845Speter#define	__unused
1962059Sdg#endif
197126891Strhodes#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
19883443Sasmodai#define	__dead2		__attribute__((__noreturn__))
19983443Sasmodai#define	__pure2		__attribute__((__const__))
20083443Sasmodai#define	__unused
201103845Speter/* XXX Find out what to do for __packed, __aligned and __section */
2021541Srgrimes#endif
203120608Smux#if __GNUC_PREREQ__(2, 7)
20483443Sasmodai#define	__dead2		__attribute__((__noreturn__))
20583443Sasmodai#define	__pure2		__attribute__((__const__))
20683443Sasmodai#define	__unused	__attribute__((__unused__))
207132782Skan#define	__used		__attribute__((__used__))
208103834Speter#define	__packed	__attribute__((__packed__))
209103834Speter#define	__aligned(x)	__attribute__((__aligned__(x)))
210103836Speter#define	__section(x)	__attribute__((__section__(x)))
21117648Speter#endif
212126891Strhodes#if defined(__INTEL_COMPILER)
213126891Strhodes#define __dead2		__attribute__((__noreturn__))
214126891Strhodes#define __pure2		__attribute__((__const__))
215126891Strhodes#define __unused	__attribute__((__unused__))
216132782Skan#define __used		__attribute__((__used__))
217126891Strhodes#define __packed	__attribute__((__packed__))
218126891Strhodes#define __aligned(x)	__attribute__((__aligned__(x)))
219126891Strhodes#define __section(x)	__attribute__((__section__(x)))
220103845Speter#endif
221126891Strhodes#endif
2221541Srgrimes
223132538Stjr#if __GNUC_PREREQ__(2, 96)
224187961Sdas#define	__malloc_like	__attribute__((__malloc__))
225132538Stjr#define	__pure		__attribute__((__pure__))
226132538Stjr#else
227187961Sdas#define	__malloc_like
228132538Stjr#define	__pure
229132538Stjr#endif
230132538Stjr
231126891Strhodes#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
232117906Speter#define	__always_inline	__attribute__((__always_inline__))
233117906Speter#else
234117906Speter#define	__always_inline
235117906Speter#endif
236117906Speter
237177618Ssam#if __GNUC_PREREQ__(3, 1)
238177618Ssam#define	__noinline	__attribute__ ((__noinline__))
239177618Ssam#else
240177618Ssam#define	__noinline
241177618Ssam#endif
242177618Ssam
243120608Smux#if __GNUC_PREREQ__(3, 3)
244117837Sphk#define __nonnull(x)	__attribute__((__nonnull__(x)))
245117837Sphk#else
246117837Sphk#define __nonnull(x)
247117837Sphk#endif
248117837Sphk
24985672Smike/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
250126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
25185672Smike#define	__func__	NULL
25285672Smike#endif
25385672Smike
254126891Strhodes#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
25586302Smike#define	__LONG_LONG_SUPPORTED
25686302Smike#endif
25786302Smike
25838509Sbde/*
259104591Smike * GCC 2.95 provides `__restrict' as an extension to C90 to support the
260103370Swollman * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
261103370Swollman * a way to define the `restrict' type qualifier without disturbing older
262103370Swollman * software that is unaware of C99 keywords.
26386803Smike */
26486803Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
265189247Sed#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
26686803Smike#define	__restrict
26786803Smike#else
26886803Smike#define	__restrict	restrict
26986803Smike#endif
27086803Smike#endif
27186803Smike
27286803Smike/*
273120609Smux * GNU C version 2.96 adds explicit branch prediction so that
274120609Smux * the CPU back-end can hint the processor and also so that
275120609Smux * code blocks can be reordered such that the predicted path
276120609Smux * sees a more linear flow, thus improving cache behavior, etc.
277120609Smux *
278120609Smux * The following two macros provide us with a way to utilize this
279120609Smux * compiler feature.  Use __predict_true() if you expect the expression
280120609Smux * to evaluate to true, and __predict_false() if you expect the
281120609Smux * expression to evaluate to false.
282120609Smux *
283120609Smux * A few notes about usage:
284120609Smux *
285120609Smux *	* Generally, __predict_false() error condition checks (unless
286120609Smux *	  you have some _strong_ reason to do otherwise, in which case
287120609Smux *	  document it), and/or __predict_true() `no-error' condition
288120609Smux *	  checks, assuming you want to optimize for the no-error case.
289120609Smux *
290120609Smux *	* Other than that, if you don't know the likelihood of a test
291120609Smux *	  succeeding from empirical or other `hard' evidence, don't
292120609Smux *	  make predictions.
293120609Smux *
294120609Smux *	* These are meant to be used in places that are run `a lot'.
295120609Smux *	  It is wasteful to make predictions in code that is run
296120609Smux *	  seldomly (e.g. at subsystem initialization time) as the
297120609Smux *	  basic block reordering that this affects can often generate
298120609Smux *	  larger code.
299120609Smux */
300120609Smux#if __GNUC_PREREQ__(2, 96)
301120609Smux#define __predict_true(exp)     __builtin_expect((exp), 1)
302120609Smux#define __predict_false(exp)    __builtin_expect((exp), 0)
303120609Smux#else
304120609Smux#define __predict_true(exp)     (exp)
305120609Smux#define __predict_false(exp)    (exp)
306120609Smux#endif
307120609Smux
308211335Skib#if __GNUC_PREREQ__(4, 2)
309211335Skib#define	__hidden	__attribute((visibility("hidden")))
310211335Skib#define	__exported	__attribute((visibility("default")))
311211335Skib#else
312211335Skib#define	__hidden
313211335Skib#define	__exported
314211335Skib#endif
315211335Skib
316120609Smux/*
31799594Smike * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
31899594Smike * require it.
31999594Smike */
320162488Skan#if __GNUC_PREREQ__(4, 1)
321162488Skan#define __offsetof(type, field)	 __builtin_offsetof(type, field)
322162488Skan#else
323146941Skan#ifndef __cplusplus
32499594Smike#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
325146941Skan#else
326146941Skan#define __offsetof(type, field)					\
327146941Skan  (__offsetof__ (reinterpret_cast <size_t>			\
328146941Skan                 (&reinterpret_cast <const volatile char &>	\
329146941Skan                  (static_cast<type *> (0)->field))))
330146941Skan#endif
331162488Skan#endif
332133604Sjulian#define	__rangeof(type, start, end) \
333133604Sjulian	(__offsetof(type, end) - __offsetof(type, start))
33499594Smike
33599594Smike/*
33638509Sbde * Compiler-dependent macros to declare that functions take printf-like
33738509Sbde * or scanf-like arguments.  They are null except for versions of gcc
33838509Sbde * that are known to support the features properly (old versions of gcc-2
33938509Sbde * didn't permit keeping the keywords out of the application namespace).
34038509Sbde */
341126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
34237614Sbde#define	__printflike(fmtarg, firstvararg)
34337614Sbde#define	__scanflike(fmtarg, firstvararg)
344154867Sstefanf#define	__format_arg(fmtarg)
34537614Sbde#else
34637614Sbde#define	__printflike(fmtarg, firstvararg) \
34737614Sbde	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
34837614Sbde#define	__scanflike(fmtarg, firstvararg) \
34937614Sbde	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
350154867Sstefanf#define	__format_arg(fmtarg)	__attribute__((__format_arg__ (fmtarg)))
35137614Sbde#endif
35237614Sbde
35340716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
354126891Strhodes#if __FreeBSD_cc_version >= 300001 && defined(__GNUC__) && !defined(__INTEL_COMPILER)
35540716Sjdp#define	__printf0like(fmtarg, firstvararg) \
35640716Sjdp	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
35740716Sjdp#else
35840716Sjdp#define	__printf0like(fmtarg, firstvararg)
35940716Sjdp#endif
36040716Sjdp
361126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER)
362126891Strhodes#ifndef __INTEL_COMPILER
36383443Sasmodai#define	__strong_reference(sym,aliassym)	\
364148005Skbyanc	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
365126891Strhodes#endif
3665209Snate#ifdef __STDC__
367209876Snwhitehorn#ifdef __powerpc64__
36837052Speter#define	__weak_reference(sym,alias)	\
36937052Speter	__asm__(".weak " #alias);	\
370209876Snwhitehorn	__asm__(".equ "  #alias ", " #sym); \
371209876Snwhitehorn	__asm__(".weak ." #alias);	\
372209876Snwhitehorn	__asm__(".equ ."  #alias ", ." #sym)
373209876Snwhitehorn#else
374209876Snwhitehorn#define	__weak_reference(sym,alias)	\
375209876Snwhitehorn	__asm__(".weak " #alias);	\
37637862Sdfr	__asm__(".equ "  #alias ", " #sym)
377209876Snwhitehorn#endif
378209876Snwhitehorn#define	__weak_reference_data(sym,alias)\
379209876Snwhitehorn	__asm__(".weak " #alias);	\
380209876Snwhitehorn	__asm__(".equ "  #alias ", " #sym)
38137052Speter#define	__warn_references(sym,msg)	\
38237052Speter	__asm__(".section .gnu.warning." #sym);	\
38339502Sjdp	__asm__(".asciz \"" msg "\"");	\
38437052Speter	__asm__(".previous")
385156607Sdeischen#define	__sym_compat(sym,impl,verid)	\
386156607Sdeischen	__asm__(".symver " #impl ", " #sym "@" #verid)
387156607Sdeischen#define	__sym_default(sym,impl,verid)	\
388156607Sdeischen	__asm__(".symver " #impl ", " #sym "@@" #verid)
38937052Speter#else
39037052Speter#define	__weak_reference(sym,alias)	\
39137052Speter	__asm__(".weak alias");		\
39237862Sdfr	__asm__(".equ alias, sym")
39337052Speter#define	__warn_references(sym,msg)	\
39437052Speter	__asm__(".section .gnu.warning.sym"); \
39539502Sjdp	__asm__(".asciz \"msg\"");	\
39637052Speter	__asm__(".previous")
397156607Sdeischen#define	__sym_compat(sym,impl,verid)	\
398156607Sdeischen	__asm__(".symver impl, sym@verid")
399156607Sdeischen#define	__sym_default(impl,sym,verid)	\
400156607Sdeischen	__asm__(".symver impl, sym@@verid")
40137052Speter#endif	/* __STDC__ */
402126891Strhodes#endif	/* __GNUC__ || __INTEL_COMPILER */
4035209Snate
404126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER)
40550614Speter#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
40650614Speter#else
40783049Speter/*
408118023Sgad * The following definition might not work well if used in header files,
409118023Sgad * but it should be better than nothing.  If you want a "do nothing"
410118023Sgad * version, then it should generate some harmless declaration, such as:
411118023Sgad *    #define __IDSTRING(name,string)	struct __hack
41283049Speter */
41336971Sbde#define	__IDSTRING(name,string)	static const char name[] __unused = string
41450614Speter#endif
41531707Spst
41683552Sdillon/*
41783552Sdillon * Embed the rcs id of a source file in the resulting library.  Note that in
41883552Sdillon * more recent ELF binutils, we use .ident allowing the ID to be stripped.
41983552Sdillon * Usage:
42083552Sdillon *	__FBSDID("$FreeBSD: head/sys/sys/cdefs.h 211335 2010-08-15 14:38:01Z kib $");
42183552Sdillon */
42283489Sdillon#ifndef	__FBSDID
42383528Sobrien#if !defined(lint) && !defined(STRIP_FBSDID)
42483526Sobrien#define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
42583489Sdillon#else
42683552Sdillon#define	__FBSDID(s)	struct __hack
42783489Sdillon#endif
42883489Sdillon#endif
42983489Sdillon
43093996Sobrien#ifndef	__RCSID
43193996Sobrien#ifndef	NO__RCSID
43293993Sobrien#define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
43393996Sobrien#else
434118023Sgad#define	__RCSID(s)	struct __hack
43593993Sobrien#endif
43693996Sobrien#endif
43793993Sobrien
43893996Sobrien#ifndef	__RCSID_SOURCE
43993996Sobrien#ifndef	NO__RCSID_SOURCE
44083049Speter#define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
44193996Sobrien#else
442118023Sgad#define	__RCSID_SOURCE(s)	struct __hack
44331707Spst#endif
44493996Sobrien#endif
44531707Spst
44693996Sobrien#ifndef	__SCCSID
44793996Sobrien#ifndef	NO__SCCSID
44893996Sobrien#define	__SCCSID(s)	__IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
44993996Sobrien#else
450118023Sgad#define	__SCCSID(s)	struct __hack
45193996Sobrien#endif
45293996Sobrien#endif
45393996Sobrien
45493996Sobrien#ifndef	__COPYRIGHT
45593996Sobrien#ifndef	NO__COPYRIGHT
45683049Speter#define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
45793996Sobrien#else
458118023Sgad#define	__COPYRIGHT(s)	struct __hack
45931707Spst#endif
46093996Sobrien#endif
46131707Spst
46274070Sbillf#ifndef	__DECONST
46374070Sbillf#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
46474070Sbillf#endif
46574070Sbillf
46674070Sbillf#ifndef	__DEVOLATILE
46774070Sbillf#define	__DEVOLATILE(type, var)	((type)(uintptr_t)(volatile void *)(var))
46874070Sbillf#endif
46974070Sbillf
47074070Sbillf#ifndef	__DEQUALIFY
47174070Sbillf#define	__DEQUALIFY(type, var)	((type)(uintptr_t)(const volatile void *)(var))
47274070Sbillf#endif
47374070Sbillf
474210226Strasz/*-
47593510Smike * The following definitions are an extension of the behavior originally
47699904Smikeh * implemented in <sys/_posix.h>, but with a different level of granularity.
47793510Smike * POSIX.1 requires that the macros we test be defined before any standard
47893510Smike * header file is included.
47993510Smike *
48093510Smike * Here's a quick run-down of the versions:
48193510Smike *  defined(_POSIX_SOURCE)		1003.1-1988
48293510Smike *  _POSIX_C_SOURCE == 1		1003.1-1990
483100109Swollman *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
48493510Smike *  _POSIX_C_SOURCE == 199309		1003.1b-1993
48593510Smike *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
48693510Smike *					and the omnibus ISO/IEC 9945-1: 1996
48793510Smike *  _POSIX_C_SOURCE == 200112		1003.1-2001
488189134Sdas *  _POSIX_C_SOURCE == 200809		1003.1-2008
48993510Smike *
49093510Smike * In addition, the X/Open Portability Guide, which is now the Single UNIX
49193510Smike * Specification, defines a feature-test macro which indicates the version of
49293510Smike * that specification, and which subsumes _POSIX_C_SOURCE.
49393510Smike *
49493510Smike * Our macros begin with two underscores to avoid namespace screwage.
49593510Smike */
49693510Smike
49793510Smike/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
498121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
49993510Smike#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
50093510Smike#define	_POSIX_C_SOURCE		199009
50193510Smike#endif
50293510Smike
503100109Swollman/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
504121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
505100109Swollman#undef _POSIX_C_SOURCE
506100109Swollman#define	_POSIX_C_SOURCE		199209
507100109Swollman#endif
508100109Swollman
50993510Smike/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
51093510Smike#ifdef _XOPEN_SOURCE
511189134Sdas#if _XOPEN_SOURCE - 0 >= 700
512189134Sdas#define	__XSI_VISIBLE		700
513189134Sdas#undef _POSIX_C_SOURCE
514189134Sdas#define	_POSIX_C_SOURCE		200809
515189134Sdas#elif _XOPEN_SOURCE - 0 >= 600
51693510Smike#define	__XSI_VISIBLE		600
51793510Smike#undef _POSIX_C_SOURCE
51893510Smike#define	_POSIX_C_SOURCE		200112
51993715Speter#elif _XOPEN_SOURCE - 0 >= 500
52093510Smike#define	__XSI_VISIBLE		500
52193510Smike#undef _POSIX_C_SOURCE
52293510Smike#define	_POSIX_C_SOURCE		199506
52393510Smike#endif
52493510Smike#endif
52593510Smike
52693510Smike/*
52793510Smike * Deal with all versions of POSIX.  The ordering relative to the tests above is
52893510Smike * important.
52993510Smike */
53093510Smike#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
53193510Smike#define	_POSIX_C_SOURCE		198808
53293510Smike#endif
53393510Smike#ifdef _POSIX_C_SOURCE
534189134Sdas#if _POSIX_C_SOURCE >= 200809
535189134Sdas#define	__POSIX_VISIBLE		200809
536189134Sdas#define	__ISO_C_VISIBLE		1999
537189209Sdas#elif _POSIX_C_SOURCE >= 200112
53893510Smike#define	__POSIX_VISIBLE		200112
53993510Smike#define	__ISO_C_VISIBLE		1999
54093510Smike#elif _POSIX_C_SOURCE >= 199506
54193510Smike#define	__POSIX_VISIBLE		199506
54293510Smike#define	__ISO_C_VISIBLE		1990
54393510Smike#elif _POSIX_C_SOURCE >= 199309
54493510Smike#define	__POSIX_VISIBLE		199309
54593510Smike#define	__ISO_C_VISIBLE		1990
546100109Swollman#elif _POSIX_C_SOURCE >= 199209
547100109Swollman#define	__POSIX_VISIBLE		199209
548100109Swollman#define	__ISO_C_VISIBLE		1990
54993510Smike#elif _POSIX_C_SOURCE >= 199009
55093510Smike#define	__POSIX_VISIBLE		199009
55193510Smike#define	__ISO_C_VISIBLE		1990
55293510Smike#else
55393510Smike#define	__POSIX_VISIBLE		198808
55493510Smike#define	__ISO_C_VISIBLE		0
55593510Smike#endif /* _POSIX_C_SOURCE */
55693510Smike#else
557210226Strasz/*-
55893510Smike * Deal with _ANSI_SOURCE:
55993510Smike * If it is defined, and no other compilation environment is explicitly
56093510Smike * requested, then define our internal feature-test macros to zero.  This
56193510Smike * makes no difference to the preprocessor (undefined symbols in preprocessing
56293510Smike * expressions are defined to have value zero), but makes it more convenient for
56393510Smike * a test program to print out the values.
56493510Smike *
56593510Smike * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
56693510Smike * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
56793510Smike * environment (and in fact we will never get here).
56893510Smike */
569105654Smike#if defined(_ANSI_SOURCE)	/* Hide almost everything. */
57093510Smike#define	__POSIX_VISIBLE		0
57193510Smike#define	__XSI_VISIBLE		0
57293510Smike#define	__BSD_VISIBLE		0
57393510Smike#define	__ISO_C_VISIBLE		1990
574105654Smike#elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
575105654Smike#define	__POSIX_VISIBLE		0
576105654Smike#define	__XSI_VISIBLE		0
577105654Smike#define	__BSD_VISIBLE		0
578105654Smike#define	__ISO_C_VISIBLE		1999
57993510Smike#else				/* Default environment: show everything. */
580189134Sdas#define	__POSIX_VISIBLE		200809
581189134Sdas#define	__XSI_VISIBLE		700
58293510Smike#define	__BSD_VISIBLE		1
58393510Smike#define	__ISO_C_VISIBLE		1999
58493510Smike#endif
58593510Smike#endif
58693510Smike
5872212Sbde#endif /* !_SYS_CDEFS_H_ */
588