cdefs.h revision 103841
11541Srgrimes/*
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 * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
3614495Shsu *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
3750477Speter * $FreeBSD: head/sys/sys/cdefs.h 103841 2002-09-23 06:19:31Z peter $
381541Srgrimes */
391541Srgrimes
402165Spaul#ifndef	_SYS_CDEFS_H_
412165Spaul#define	_SYS_CDEFS_H_
421541Srgrimes
431541Srgrimes#if defined(__cplusplus)
441541Srgrimes#define	__BEGIN_DECLS	extern "C" {
4536449Sdt#define	__END_DECLS	}
461541Srgrimes#else
471541Srgrimes#define	__BEGIN_DECLS
481541Srgrimes#define	__END_DECLS
491541Srgrimes#endif
501541Srgrimes
511541Srgrimes/*
521541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
531541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
5436971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
5536971Sbde * mode -- there must be no spaces between its arguments, and for nested
5636971Sbde * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
5736971Sbde * concatenate double-quoted strings produced by the __STRING macro, but
5836971Sbde * this only works with ANSI C.
5925083Sjdp *
6025083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument
6125083Sjdp * first.  It is only available with ANSI C.
621541Srgrimes */
631541Srgrimes#if defined(__STDC__) || defined(__cplusplus)
641541Srgrimes#define	__P(protos)	protos		/* full-blown ANSI C */
655012Sbde#define	__CONCAT1(x,y)	x ## y
665012Sbde#define	__CONCAT(x,y)	__CONCAT1(x,y)
6725083Sjdp#define	__STRING(x)	#x		/* stringify without expanding x */
6825083Sjdp#define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
691541Srgrimes
701541Srgrimes#define	__const		const		/* define reserved names to standard */
711541Srgrimes#define	__signed	signed
721541Srgrimes#define	__volatile	volatile
731541Srgrimes#if defined(__cplusplus)
741541Srgrimes#define	__inline	inline		/* convert to C++ keyword */
751541Srgrimes#else
761541Srgrimes#ifndef __GNUC__
771541Srgrimes#define	__inline			/* delete GCC keyword */
781541Srgrimes#endif /* !__GNUC__ */
791541Srgrimes#endif /* !__cplusplus */
801541Srgrimes
811541Srgrimes#else	/* !(__STDC__ || __cplusplus) */
821541Srgrimes#define	__P(protos)	()		/* traditional C preprocessor */
831541Srgrimes#define	__CONCAT(x,y)	x/**/y
841541Srgrimes#define	__STRING(x)	"x"
851541Srgrimes
861541Srgrimes#ifndef __GNUC__
871541Srgrimes#define	__const				/* delete pseudo-ANSI C keywords */
881541Srgrimes#define	__inline
891541Srgrimes#define	__signed
901541Srgrimes#define	__volatile
911541Srgrimes/*
921541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords
931541Srgrimes * deleted from the program and old programs will want them left alone.
941541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords
951541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
961541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if
971541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
981541Srgrimes */
991541Srgrimes#ifndef	NO_ANSI_KEYWORDS
1001541Srgrimes#define	const				/* delete ANSI C keywords */
1011541Srgrimes#define	inline
1021541Srgrimes#define	signed
1031541Srgrimes#define	volatile
1045209Snate#endif	/* !NO_ANSI_KEYWORDS */
10515243Sbde#endif	/* !__GNUC__ */
1061541Srgrimes#endif	/* !(__STDC__ || __cplusplus) */
1071541Srgrimes
1081541Srgrimes/*
10938509Sbde * Compiler-dependent macros to help declare dead (non-returning) and
11038509Sbde * pure (no side effects) functions, and unused variables.  They are
11138509Sbde * null except for versions of gcc that are known to support the features
11238509Sbde * properly (old versions of gcc-2 supported the dead and pure features
11338509Sbde * in a different (wrong) way).
1141541Srgrimes */
11538509Sbde#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5
11683443Sasmodai#define	__dead2
11783443Sasmodai#define	__pure2
11883443Sasmodai#define	__unused
119103834Speter#define	__packed
120103836Speter#define	__aligned(x)
121103841Speter#define	__section(x)
1222059Sdg#endif
12317648Speter#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7
12483443Sasmodai#define	__dead2		__attribute__((__noreturn__))
12583443Sasmodai#define	__pure2		__attribute__((__const__))
12683443Sasmodai#define	__unused
127103836Speter#define	__packed	/* XXX find this out, if we care */
128103836Speter#define	__aligned(x)	/* XXX find this out, if we care */
129103841Speter#define	__section(x)	/* XXX find this out, if we care */
1301541Srgrimes#endif
13177631Sobrien#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3
13283443Sasmodai#define	__dead2		__attribute__((__noreturn__))
13383443Sasmodai#define	__pure2		__attribute__((__const__))
13483443Sasmodai#define	__unused	__attribute__((__unused__))
135103834Speter#define	__packed	__attribute__((__packed__))
136103834Speter#define	__aligned(x)	__attribute__((__aligned__(x)))
137103836Speter#define	__section(x)	__attribute__((__section__(x)))
13817648Speter#endif
1391541Srgrimes
14085672Smike/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
14185672Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
14285672Smike#define	__func__	NULL
14385672Smike#endif
14485672Smike
145103345Sbde#if __GNUC__ >= 2 && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
14686302Smike#define	__LONG_LONG_SUPPORTED
14786302Smike#endif
14886302Smike
14938509Sbde/*
15086803Smike * GCC 2.95 provides `__restrict' as an extention to C90 to support the
151103370Swollman * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
152103370Swollman * a way to define the `restrict' type qualifier without disturbing older
153103370Swollman * software that is unaware of C99 keywords.
15486803Smike */
15586803Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
15686803Smike#if __STDC_VERSION__ < 199901
15786803Smike#define	__restrict
15886803Smike#else
15986803Smike#define	__restrict	restrict
16086803Smike#endif
16186803Smike#endif
16286803Smike
16386803Smike/*
16499594Smike * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
16599594Smike * require it.
16699594Smike */
16799594Smike#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
16899594Smike
16999594Smike/*
17038509Sbde * Compiler-dependent macros to declare that functions take printf-like
17138509Sbde * or scanf-like arguments.  They are null except for versions of gcc
17238509Sbde * that are known to support the features properly (old versions of gcc-2
17338509Sbde * didn't permit keeping the keywords out of the application namespace).
17438509Sbde */
17537614Sbde#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7
17637614Sbde#define	__printflike(fmtarg, firstvararg)
17737614Sbde#define	__scanflike(fmtarg, firstvararg)
17837614Sbde#else
17937614Sbde#define	__printflike(fmtarg, firstvararg) \
18037614Sbde	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
18137614Sbde#define	__scanflike(fmtarg, firstvararg) \
18237614Sbde	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
18337614Sbde#endif
18437614Sbde
18540716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
18699755Sdillon#if __FreeBSD_cc_version >= 300001 && __FreeBSD_cc_version < 500003
18740716Sjdp#define	__printf0like(fmtarg, firstvararg) \
18840716Sjdp	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
18940716Sjdp#else
19040716Sjdp#define	__printf0like(fmtarg, firstvararg)
19140716Sjdp#endif
19240716Sjdp
1935209Snate#ifdef __GNUC__
19483443Sasmodai#define	__strong_reference(sym,aliassym)	\
19558256Sjasone	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)));
1965209Snate#ifdef __STDC__
19737052Speter#define	__weak_reference(sym,alias)	\
19837052Speter	__asm__(".weak " #alias);	\
19937862Sdfr	__asm__(".equ "  #alias ", " #sym)
20037052Speter#define	__warn_references(sym,msg)	\
20137052Speter	__asm__(".section .gnu.warning." #sym);	\
20239502Sjdp	__asm__(".asciz \"" msg "\"");	\
20337052Speter	__asm__(".previous")
20437052Speter#else
20537052Speter#define	__weak_reference(sym,alias)	\
20637052Speter	__asm__(".weak alias");		\
20737862Sdfr	__asm__(".equ alias, sym")
20837052Speter#define	__warn_references(sym,msg)	\
20937052Speter	__asm__(".section .gnu.warning.sym"); \
21039502Sjdp	__asm__(".asciz \"msg\"");	\
21137052Speter	__asm__(".previous")
21237052Speter#endif	/* __STDC__ */
21337052Speter#endif	/* __GNUC__ */
2145209Snate
21583049Speter#ifdef __GNUC__
21650614Speter#define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
21750614Speter#else
21883049Speter/*
21983049Speter * This doesn't work in header files. But it may be better than nothing.
22083056Speter * The alternative is: #define __IDSTRING(name,string)  [nothing]
22183049Speter */
22236971Sbde#define	__IDSTRING(name,string)	static const char name[] __unused = string
22350614Speter#endif
22431707Spst
22583552Sdillon/*
22683552Sdillon * Embed the rcs id of a source file in the resulting library.  Note that in
22783552Sdillon * more recent ELF binutils, we use .ident allowing the ID to be stripped.
22883552Sdillon * Usage:
22983552Sdillon *	__FBSDID("$FreeBSD: head/sys/sys/cdefs.h 103841 2002-09-23 06:19:31Z peter $");
23083552Sdillon */
23183489Sdillon#ifndef	__FBSDID
23283528Sobrien#if !defined(lint) && !defined(STRIP_FBSDID)
23383526Sobrien#define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
23483489Sdillon#else
23583552Sdillon#define	__FBSDID(s)	struct __hack
23683489Sdillon#endif
23783489Sdillon#endif
23883489Sdillon
23993996Sobrien#ifndef	__RCSID
24093996Sobrien#ifndef	NO__RCSID
24193993Sobrien#define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
24293996Sobrien#else
24393996Sobrien#define	__RCSID(s)
24493993Sobrien#endif
24593996Sobrien#endif
24693993Sobrien
24793996Sobrien#ifndef	__RCSID_SOURCE
24893996Sobrien#ifndef	NO__RCSID_SOURCE
24983049Speter#define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
25093996Sobrien#else
25193996Sobrien#define	__RCSID_SOURCE(s)
25231707Spst#endif
25393996Sobrien#endif
25431707Spst
25593996Sobrien#ifndef	__SCCSID
25693996Sobrien#ifndef	NO__SCCSID
25793996Sobrien#define	__SCCSID(s)	__IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
25893996Sobrien#else
25993996Sobrien#define	__SCCSID(s)
26093996Sobrien#endif
26193996Sobrien#endif
26293996Sobrien
26393996Sobrien#ifndef	__COPYRIGHT
26493996Sobrien#ifndef	NO__COPYRIGHT
26583049Speter#define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
26693996Sobrien#else
26793996Sobrien#define	__COPYRIGHT(s)
26831707Spst#endif
26993996Sobrien#endif
27031707Spst
27174070Sbillf#ifndef	__DECONST
27274070Sbillf#define	__DECONST(type, var)	((type)(uintptr_t)(const void *)(var))
27374070Sbillf#endif
27474070Sbillf
27574070Sbillf#ifndef	__DEVOLATILE
27674070Sbillf#define	__DEVOLATILE(type, var)	((type)(uintptr_t)(volatile void *)(var))
27774070Sbillf#endif
27874070Sbillf
27974070Sbillf#ifndef	__DEQUALIFY
28074070Sbillf#define	__DEQUALIFY(type, var)	((type)(uintptr_t)(const volatile void *)(var))
28174070Sbillf#endif
28274070Sbillf
28393510Smike/*-
28493510Smike * The following definitions are an extension of the behavior originally
28599904Smikeh * implemented in <sys/_posix.h>, but with a different level of granularity.
28693510Smike * POSIX.1 requires that the macros we test be defined before any standard
28793510Smike * header file is included.
28893510Smike *
28993510Smike * Here's a quick run-down of the versions:
29093510Smike *  defined(_POSIX_SOURCE)		1003.1-1988
29193510Smike *  _POSIX_C_SOURCE == 1		1003.1-1990
292100109Swollman *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
29393510Smike *  _POSIX_C_SOURCE == 199309		1003.1b-1993
29493510Smike *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
29593510Smike *					and the omnibus ISO/IEC 9945-1: 1996
29693510Smike *  _POSIX_C_SOURCE == 200112		1003.1-2001
29793510Smike *
29893510Smike * In addition, the X/Open Portability Guide, which is now the Single UNIX
29993510Smike * Specification, defines a feature-test macro which indicates the version of
30093510Smike * that specification, and which subsumes _POSIX_C_SOURCE.
30193510Smike *
30293510Smike * Our macros begin with two underscores to avoid namespace screwage.
30393510Smike */
30493510Smike
30593510Smike/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
306100109Swollman#if _POSIX_C_SOURCE == 1
30793510Smike#undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
30893510Smike#define	_POSIX_C_SOURCE		199009
30993510Smike#endif
31093510Smike
311100109Swollman/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
312100109Swollman#if _POSIX_C_SOURCE == 2
313100109Swollman#undef _POSIX_C_SOURCE
314100109Swollman#define	_POSIX_C_SOURCE		199209
315100109Swollman#endif
316100109Swollman
31793510Smike/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
31893510Smike#ifdef _XOPEN_SOURCE
31993715Speter#if _XOPEN_SOURCE - 0 >= 600
32093510Smike#define	__XSI_VISIBLE		600
32193510Smike#undef _POSIX_C_SOURCE
32293510Smike#define	_POSIX_C_SOURCE		200112
32393715Speter#elif _XOPEN_SOURCE - 0 >= 500
32493510Smike#define	__XSI_VISIBLE		500
32593510Smike#undef _POSIX_C_SOURCE
32693510Smike#define	_POSIX_C_SOURCE		199506
32793510Smike#endif
32893510Smike#endif
32993510Smike
33093510Smike/*
33193510Smike * Deal with all versions of POSIX.  The ordering relative to the tests above is
33293510Smike * important.
33393510Smike */
33493510Smike#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
33593510Smike#define	_POSIX_C_SOURCE		198808
33693510Smike#endif
33793510Smike#ifdef _POSIX_C_SOURCE
33893510Smike#if _POSIX_C_SOURCE >= 200112
33993510Smike#define	__POSIX_VISIBLE		200112
34093510Smike#define	__ISO_C_VISIBLE		1999
34193510Smike#elif _POSIX_C_SOURCE >= 199506
34293510Smike#define	__POSIX_VISIBLE		199506
34393510Smike#define	__ISO_C_VISIBLE		1990
34493510Smike#elif _POSIX_C_SOURCE >= 199309
34593510Smike#define	__POSIX_VISIBLE		199309
34693510Smike#define	__ISO_C_VISIBLE		1990
347100109Swollman#elif _POSIX_C_SOURCE >= 199209
348100109Swollman#define	__POSIX_VISIBLE		199209
349100109Swollman#define	__ISO_C_VISIBLE		1990
35093510Smike#elif _POSIX_C_SOURCE >= 199009
35193510Smike#define	__POSIX_VISIBLE		199009
35293510Smike#define	__ISO_C_VISIBLE		1990
35393510Smike#else
35493510Smike#define	__POSIX_VISIBLE		198808
35593510Smike#define	__ISO_C_VISIBLE		0
35693510Smike#endif /* _POSIX_C_SOURCE */
35793510Smike#else
35893510Smike/*-
35993510Smike * Deal with _ANSI_SOURCE:
36093510Smike * If it is defined, and no other compilation environment is explicitly
36193510Smike * requested, then define our internal feature-test macros to zero.  This
36293510Smike * makes no difference to the preprocessor (undefined symbols in preprocessing
36393510Smike * expressions are defined to have value zero), but makes it more convenient for
36493510Smike * a test program to print out the values.
36593510Smike *
36693510Smike * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
36793510Smike * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
36893510Smike * environment (and in fact we will never get here).
36993510Smike */
37093510Smike#ifdef _ANSI_SOURCE		/* Hide almost everything. */
37193510Smike#define	__POSIX_VISIBLE		0
37293510Smike#define	__XSI_VISIBLE		0
37393510Smike#define	__BSD_VISIBLE		0
37493510Smike#define	__ISO_C_VISIBLE		1990
37593510Smike#else				/* Default environment: show everything. */
37693510Smike#define	__POSIX_VISIBLE		200112
37793510Smike#define	__XSI_VISIBLE		600
37893510Smike#define	__BSD_VISIBLE		1
37993510Smike#define	__ISO_C_VISIBLE		1999
38093510Smike#endif
38193510Smike#endif
38293510Smike
3832212Sbde#endif /* !_SYS_CDEFS_H_ */
384