diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/sys/cdefs.h | 152 |
1 files changed, 151 insertions, 1 deletions
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h index 1c90d8ee2ae..323108c1953 100644 --- a/sys/sys/cdefs.h +++ b/sys/sys/cdefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cdefs.h,v 1.15 2005/05/19 18:32:51 hshoexer Exp $ */ +/* $OpenBSD: cdefs.h,v 1.16 2005/05/24 22:28:02 millert Exp $ */ /* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */ /* @@ -179,4 +179,154 @@ #define __extension__ #endif +/* + * "The nice thing about standards is that there are so many to choose from." + * There are a number of "feature test macros" specified by (different) + * standards that determine which interfaces and types the header files + * should expose. + * + * Because of inconsistencies in these macros, we define our own + * set in the private name space that end in _VISIBLE. These are + * always defined and so headers can test their values easily. + * Things can get tricky when multiple feature macros are defined. + * We try to take the union of all the features requested. + * + * The following macros are guaranteed to have a value after cdefs.h + * has been included: + * __POSIX_VISIBLE + * __XPG_VISIBLE + * __ISO_C_VISIBLE + * __OPENBSD_VISIBLE + */ + +/* + * X/Open Portability Guides and Single Unix Specifications. + * _XOPEN_SOURCE XPG3 + * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4 + * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2 + * _XOPEN_SOURCE == 500 XPG5 + * _XOPEN_SOURCE == 520 XPG5v2 + * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI + * + * The XPG spec implies a specific value for _POSIX_C_SOURCE. + */ +#ifdef _XOPEN_SOURCE +# if (_XOPEN_SOURCE - 0 >= 600) +# define __XPG_VISIBLE 600 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +# elif (_XOPEN_SOURCE - 0 >= 520) +# define __XPG_VISIBLE 520 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506L +# elif (_XOPEN_SOURCE - 0 >= 500) +# define __XPG_VISIBLE 500 +# undef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506L +# elif (_XOPEN_SOURCE_EXTENDED - 0 == 1) +# define __XPG_VISIBLE 420 +# elif (_XOPEN_VERSION - 0 >= 4) +# define __XPG_VISIBLE 400 +# else +# define __XPG_VISIBLE 300 +# endif +#endif + +/* + * POSIX macros, these checks must follow the XOPEN ones above. + * + * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE) + * _POSIX_C_SOURCE == 1 1003.1-1990 + * _POSIX_C_SOURCE == 2 1003.2-1992 + * _POSIX_C_SOURCE == 199309L 1003.1b-1993 + * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, + * and the omnibus ISO/IEC 9945-1:1996 + * _POSIX_C_SOURCE == 200112L 1003.1-2001 + * + * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though + * this may be overridden by the _ISOC99_SOURCE macro later. + */ +#ifdef _POSIX_C_SOURCE +# if (_POSIX_C_SOURCE - 0 >= 200112) +# define __POSIX_VISIBLE 200112 +# define __ISO_C_VISIBLE 1999 +# elif (_POSIX_C_SOURCE - 0 >= 199506) +# define __POSIX_VISIBLE 199506 +# define __ISO_C_VISIBLE 1990 +# elif (_POSIX_C_SOURCE - 0 >= 199309) +# define __POSIX_VISIBLE 199309 +# define __ISO_C_VISIBLE 1990 +# elif (_POSIX_C_SOURCE - 0 >= 2) +# define __POSIX_VISIBLE 199209 +# define __ISO_C_VISIBLE 1990 +# else +# define __POSIX_VISIBLE 199009 +# define __ISO_C_VISIBLE 1990 +# endif +#elif defined(_POSIX_SOURCE) +# define __POSIX_VISIBLE 198808 +# define __ISO_C_VISIBLE 0 +#endif + +/* + * _ANSI_SOURCE means to expose ANSI C89 interfaces only. + * If the the user defines it in addition to one of the POSIX or XOPEN + * macros, assume the POSIX/XOPEN macro(s) should take precedence. + */ +#if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \ + !defined(__XPG_VISIBLE) +# define __POSIX_VISIBLE 0 +# define __XPG_VISIBLE 0 +# define __ISO_C_VISIBLE 1990 +#endif + +/* + * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since + * they are non-exclusive. + */ +#if defined(_ISOC99_SOURCE) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) +# undef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 1999 +#endif + +/* + * Finally deal with BSD-specific interfaces that are not covered + * by any standards. We expose these when one of the POSIX or XPG + * macros is not defined or if the user explicitly asks for them. + */ +#if !defined(_OPENBSD_SOURCE) && \ + (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE)) +# define __OPENBSD_VISIBLE 0 +#endif + +/* + * __STRICT_ANSI__ (gcc -ansi) overrides everything else. + */ +#ifdef __STRICT_ANSI__ +# undef __POSIX_VISIBLE +# define __POSIX_VISIBLE 0 +# undef __XPG_VISIBLE +# define __XPG_VISIBLE 0 +# undef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 1990 +# undef __OPENBSD_VISIBLE +# define __OPENBSD_VISIBLE 0 +#endif + +/* + * Default values. + */ +#ifndef __XPG_VISIBLE +# define __XPG_VISIBLE 600 +#endif +#ifndef __POSIX_VISIBLE +# define __POSIX_VISIBLE 200112 +#endif +#ifndef __ISO_C_VISIBLE +# define __ISO_C_VISIBLE 1999 +#endif +#ifndef __OPENBSD_VISIBLE +# define __OPENBSD_VISIBLE 1 +#endif + #endif /* !_CDEFS_H_ */ |