17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52b6e762cSahl  * Common Development and Distribution License (the "License").
62b6e762cSahl  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
212b6e762cSahl 
227c478bd9Sstevel@tonic-gate /*
23ba3594baSGarrett D'Amore  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
24fc2512cfSRobert Mustacchi  * Copyright 2016 Joyent, Inc.
25*df5cd018SRobert Mustacchi  * Copyright 2022 Oxide Computer Company
26ba3594baSGarrett D'Amore  *
272b6e762cSahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_FEATURE_TESTS_H
327c478bd9Sstevel@tonic-gate #define	_SYS_FEATURE_TESTS_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/ccompile.h>
357c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Values of _POSIX_C_SOURCE
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  *		undefined   not a POSIX compilation
457c478bd9Sstevel@tonic-gate  *		1	    POSIX.1-1990 compilation
467c478bd9Sstevel@tonic-gate  *		2	    POSIX.2-1992 compilation
477c478bd9Sstevel@tonic-gate  *		199309L	    POSIX.1b-1993 compilation (Real Time)
487c478bd9Sstevel@tonic-gate  *		199506L	    POSIX.1c-1995 compilation (POSIX Threads)
497c478bd9Sstevel@tonic-gate  *		200112L	    POSIX.1-2001 compilation (Austin Group Revision)
502d08521bSGarrett D'Amore  *		200809L     POSIX.1-2008 compilation
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
537c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE 1
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
572d08521bSGarrett D'Amore  * The feature test macros __XOPEN_OR_POSIX, _STRICT_STDC, _STRICT_SYMBOLS,
582d08521bSGarrett D'Amore  * and _STDC_C99 are Sun implementation specific macros created in order to
592d08521bSGarrett D'Amore  * compress common standards specified feature test macros for easier reading.
607c478bd9Sstevel@tonic-gate  * These macros should not be used by the application developer as
617c478bd9Sstevel@tonic-gate  * unexpected results may occur. Instead, the user should reference
62bbf21555SRichard Lowe  * standards(7) for correct usage of the standards feature test macros.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * __XOPEN_OR_POSIX     Used in cases where a symbol is defined by both
657c478bd9Sstevel@tonic-gate  *                      X/Open or POSIX or in the negative, when neither
667c478bd9Sstevel@tonic-gate  *                      X/Open or POSIX defines a symbol.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * _STRICT_STDC         __STDC__ is specified by the C Standards and defined
697c478bd9Sstevel@tonic-gate  *                      by the compiler. For Sun compilers the value of
707c478bd9Sstevel@tonic-gate  *                      __STDC__ is either 1, 0, or not defined based on the
717c478bd9Sstevel@tonic-gate  *                      compilation mode (see cc(1)). When the value of
727c478bd9Sstevel@tonic-gate  *                      __STDC__ is 1 and in the absence of any other feature
737c478bd9Sstevel@tonic-gate  *                      test macros, the namespace available to the application
747c478bd9Sstevel@tonic-gate  *                      is limited to only those symbols defined by the C
757c478bd9Sstevel@tonic-gate  *                      Standard. _STRICT_STDC provides a more readable means
767c478bd9Sstevel@tonic-gate  *                      of identifying symbols defined by the standard, or in
777c478bd9Sstevel@tonic-gate  *                      the negative, symbols that are extensions to the C
787c478bd9Sstevel@tonic-gate  *                      Standard. See additional comments for GNU C differences.
797c478bd9Sstevel@tonic-gate  *
807c478bd9Sstevel@tonic-gate  * _STDC_C99            __STDC_VERSION__ is specified by the C standards and
817c478bd9Sstevel@tonic-gate  *                      defined by the compiler and indicates the version of
827c478bd9Sstevel@tonic-gate  *                      the C standard. A value of 199901L indicates a
837c478bd9Sstevel@tonic-gate  *                      compiler that complies with ISO/IEC 9899:1999, other-
847c478bd9Sstevel@tonic-gate  *                      wise known as the C99 standard.
852d08521bSGarrett D'Amore  *
86fc2512cfSRobert Mustacchi  * _STDC_C11		Like _STDC_C99 except that the value of __STDC_VERSION__
87fc2512cfSRobert Mustacchi  *                      is 201112L indicating a compiler that compiles with
8800efb5e1SYuri Pankov  *                      ISO/IEC 9899:2011, otherwise known as the C11 standard.
89fc2512cfSRobert Mustacchi  *
902d08521bSGarrett D'Amore  * _STRICT_SYMBOLS	Used in cases where symbol visibility is restricted
912d08521bSGarrett D'Amore  *                      by the standards, and the user has not explicitly
922d08521bSGarrett D'Amore  *                      relaxed the strictness via __EXTENSIONS__.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #if defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
967c478bd9Sstevel@tonic-gate #define	__XOPEN_OR_POSIX
977c478bd9Sstevel@tonic-gate #endif
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
100fc2512cfSRobert Mustacchi  * ISO/IEC 9899:1990 and it's revisions, ISO/IEC 9899:1999 and ISO/IEC
101fc2512cfSRobert Mustacchi  * 99899:2011 specify the following predefined macro name:
1027c478bd9Sstevel@tonic-gate  *
1037c478bd9Sstevel@tonic-gate  * __STDC__	The integer constant 1, intended to indicate a conforming
1047c478bd9Sstevel@tonic-gate  *		implementation.
1057c478bd9Sstevel@tonic-gate  *
1067c478bd9Sstevel@tonic-gate  * Furthermore, a strictly conforming program shall use only those features
1077c478bd9Sstevel@tonic-gate  * of the language and library specified in these standards. A conforming
1087c478bd9Sstevel@tonic-gate  * implementation shall accept any strictly conforming program.
1097c478bd9Sstevel@tonic-gate  *
1107c478bd9Sstevel@tonic-gate  * Based on these requirements, Sun's C compiler defines __STDC__ to 1 for
1117c478bd9Sstevel@tonic-gate  * strictly conforming environments and __STDC__ to 0 for environments that
1127c478bd9Sstevel@tonic-gate  * use ANSI C semantics but allow extensions to the C standard. For non-ANSI
1137c478bd9Sstevel@tonic-gate  * C semantics, Sun's C compiler does not define __STDC__.
1147c478bd9Sstevel@tonic-gate  *
1157c478bd9Sstevel@tonic-gate  * The GNU C project interpretation is that __STDC__ should always be defined
1167c478bd9Sstevel@tonic-gate  * to 1 for compilation modes that accept ANSI C syntax regardless of whether
1177c478bd9Sstevel@tonic-gate  * or not extensions to the C standard are used. Violations of conforming
1187c478bd9Sstevel@tonic-gate  * behavior are conditionally flagged as warnings via the use of the
1197c478bd9Sstevel@tonic-gate  * -pedantic option. In addition to defining __STDC__ to 1, the GNU C
1207c478bd9Sstevel@tonic-gate  * compiler also defines __STRICT_ANSI__ as a means of specifying strictly
1217c478bd9Sstevel@tonic-gate  * conforming environments using the -ansi or -std=<standard> options.
1227c478bd9Sstevel@tonic-gate  *
1237c478bd9Sstevel@tonic-gate  * In the absence of any other compiler options, Sun and GNU set the value
1247c478bd9Sstevel@tonic-gate  * of __STDC__ as follows when using the following options:
1257c478bd9Sstevel@tonic-gate  *
1267c478bd9Sstevel@tonic-gate  *				Value of __STDC__  __STRICT_ANSI__
1277c478bd9Sstevel@tonic-gate  *
1287c478bd9Sstevel@tonic-gate  * cc -Xa (default)			0	      undefined
1297c478bd9Sstevel@tonic-gate  * cc -Xt (transitional)		0             undefined
1307c478bd9Sstevel@tonic-gate  * cc -Xc (strictly conforming)		1	      undefined
1317c478bd9Sstevel@tonic-gate  * cc -Xs (K&R C)		    undefined	      undefined
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  * gcc (default)			1	      undefined
1347c478bd9Sstevel@tonic-gate  * gcc -ansi, -std={c89, c99,...)	1               defined
1357c478bd9Sstevel@tonic-gate  * gcc -traditional (K&R)	    undefined	      undefined
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * The default compilation modes for Sun C compilers versus GNU C compilers
1387c478bd9Sstevel@tonic-gate  * results in a differing value for __STDC__ which results in a more
1397c478bd9Sstevel@tonic-gate  * restricted namespace when using Sun compilers. To allow both GNU and Sun
1407c478bd9Sstevel@tonic-gate  * interpretations to peacefully co-exist, we use the following Sun
1417c478bd9Sstevel@tonic-gate  * implementation _STRICT_STDC_ macro:
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #if (__STDC__ - 0 == 1 && !defined(__GNUC__)) || \
1457c478bd9Sstevel@tonic-gate 	(defined(__GNUC__) && defined(__STRICT_ANSI__))
1467c478bd9Sstevel@tonic-gate #define	_STRICT_STDC
1477c478bd9Sstevel@tonic-gate #else
1487c478bd9Sstevel@tonic-gate #undef	_STRICT_STDC
1497c478bd9Sstevel@tonic-gate #endif
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
152fc2512cfSRobert Mustacchi  * Compiler complies with ISO/IEC 9899:1999 or ISO/IEC 9989:2011
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate 
155fc2512cfSRobert Mustacchi #if __STDC_VERSION__ - 0 >= 201112L
156fc2512cfSRobert Mustacchi #define	_STDC_C11
157fc2512cfSRobert Mustacchi #endif
158fc2512cfSRobert Mustacchi 
1597c478bd9Sstevel@tonic-gate #if __STDC_VERSION__ - 0 >= 199901L
1607c478bd9Sstevel@tonic-gate #define	_STDC_C99
1617c478bd9Sstevel@tonic-gate #endif
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1642d08521bSGarrett D'Amore  * Use strict symbol visibility.
1652d08521bSGarrett D'Amore  */
1662d08521bSGarrett D'Amore #if (defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)) && \
1672d08521bSGarrett D'Amore 	!defined(__EXTENSIONS__)
1682d08521bSGarrett D'Amore #define	_STRICT_SYMBOLS
1692d08521bSGarrett D'Amore #endif
1702d08521bSGarrett D'Amore 
1712d08521bSGarrett D'Amore /*
172*df5cd018SRobert Mustacchi  * This is a variant of _STRICT_SYMBOLS that is meant to cover headers that are
173*df5cd018SRobert Mustacchi  * governed by POSIX, but have not been governed by ISO C. One can go two ways
174*df5cd018SRobert Mustacchi  * on what should happen if an application actively includes (not transitively)
175*df5cd018SRobert Mustacchi  * a header that isn't part of the ISO C spec, we opt to say that if someone has
176*df5cd018SRobert Mustacchi  * gone out of there way then they're doing it for a reason and that is an act
177*df5cd018SRobert Mustacchi  * of non-compliance and therefore it's not up to us to hide away every symbol.
178*df5cd018SRobert Mustacchi  *
179*df5cd018SRobert Mustacchi  * In general, prefer using _STRICT_SYMBOLS, but this is here in particular for
180*df5cd018SRobert Mustacchi  * cases where in the past we have only used a POSIX related check and we don't
181*df5cd018SRobert Mustacchi  * wish to make something stricter. Often applications are relying on the
182*df5cd018SRobert Mustacchi  * ability to, or more realistically unwittingly, have _STRICT_STDC declared and
183*df5cd018SRobert Mustacchi  * still use these interfaces.
184*df5cd018SRobert Mustacchi  */
185*df5cd018SRobert Mustacchi #if (defined(__XOPEN_OR_POSIX) && !defined(__EXTENSIONS__))
186*df5cd018SRobert Mustacchi #define	_STRICT_POSIX
187*df5cd018SRobert Mustacchi #endif
188*df5cd018SRobert Mustacchi 
189*df5cd018SRobert Mustacchi /*
1907c478bd9Sstevel@tonic-gate  * Large file interfaces:
1917c478bd9Sstevel@tonic-gate  *
1927c478bd9Sstevel@tonic-gate  *	_LARGEFILE_SOURCE
1937c478bd9Sstevel@tonic-gate  *		1		large file-related additions to POSIX
1947c478bd9Sstevel@tonic-gate  *				interfaces requested (fseeko, etc.)
1957c478bd9Sstevel@tonic-gate  *	_LARGEFILE64_SOURCE
1967c478bd9Sstevel@tonic-gate  *		1		transitional large-file-related interfaces
1977c478bd9Sstevel@tonic-gate  *				requested (seek64, stat64, etc.)
1987c478bd9Sstevel@tonic-gate  *
1997c478bd9Sstevel@tonic-gate  * The corresponding announcement macros are respectively:
2007c478bd9Sstevel@tonic-gate  *	_LFS_LARGEFILE
2017c478bd9Sstevel@tonic-gate  *	_LFS64_LARGEFILE
2027c478bd9Sstevel@tonic-gate  * (These are set in <unistd.h>.)
2037c478bd9Sstevel@tonic-gate  *
2047c478bd9Sstevel@tonic-gate  * Requesting _LARGEFILE64_SOURCE implies requesting _LARGEFILE_SOURCE as
2057c478bd9Sstevel@tonic-gate  * well.
2067c478bd9Sstevel@tonic-gate  *
2077c478bd9Sstevel@tonic-gate  * The large file interfaces are made visible regardless of the initial values
2087c478bd9Sstevel@tonic-gate  * of the feature test macros under certain circumstances:
2097c478bd9Sstevel@tonic-gate  *    -	If no explicit standards-conforming environment is requested (neither
2107c478bd9Sstevel@tonic-gate  *	of _POSIX_SOURCE nor _XOPEN_SOURCE is defined and the value of
2117c478bd9Sstevel@tonic-gate  *	__STDC__ does not imply standards conformance).
2127c478bd9Sstevel@tonic-gate  *    -	Extended system interfaces are explicitly requested (__EXTENSIONS__
2137c478bd9Sstevel@tonic-gate  *	is defined).
2147c478bd9Sstevel@tonic-gate  *    -	Access to in-kernel interfaces is requested (_KERNEL or _KMEMUSER is
2157c478bd9Sstevel@tonic-gate  *	defined).  (Note that this dependency is an artifact of the current
2167c478bd9Sstevel@tonic-gate  *	kernel implementation and may change in future releases.)
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate #if	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
2197c478bd9Sstevel@tonic-gate 		defined(_KERNEL) || defined(_KMEMUSER) || \
2207c478bd9Sstevel@tonic-gate 		defined(__EXTENSIONS__)
2217c478bd9Sstevel@tonic-gate #undef	_LARGEFILE64_SOURCE
2227c478bd9Sstevel@tonic-gate #define	_LARGEFILE64_SOURCE	1
2237c478bd9Sstevel@tonic-gate #endif
2247c478bd9Sstevel@tonic-gate #if	_LARGEFILE64_SOURCE - 0 == 1
2257c478bd9Sstevel@tonic-gate #undef	_LARGEFILE_SOURCE
2267c478bd9Sstevel@tonic-gate #define	_LARGEFILE_SOURCE	1
2277c478bd9Sstevel@tonic-gate #endif
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate  * Large file compilation environment control:
2317c478bd9Sstevel@tonic-gate  *
2327c478bd9Sstevel@tonic-gate  * The setting of _FILE_OFFSET_BITS controls the size of various file-related
2337c478bd9Sstevel@tonic-gate  * types and governs the mapping between file-related source function symbol
2347c478bd9Sstevel@tonic-gate  * names and the corresponding binary entry points.
2357c478bd9Sstevel@tonic-gate  *
2367c478bd9Sstevel@tonic-gate  * In the 32-bit environment, the default value is 32; if not set, set it to
2377c478bd9Sstevel@tonic-gate  * the default here, to simplify tests in other headers.
2387c478bd9Sstevel@tonic-gate  *
2397c478bd9Sstevel@tonic-gate  * In the 64-bit compilation environment, the only value allowed is 64.
2407c478bd9Sstevel@tonic-gate  */
2417c478bd9Sstevel@tonic-gate #if defined(_LP64)
2427c478bd9Sstevel@tonic-gate #ifndef _FILE_OFFSET_BITS
2437c478bd9Sstevel@tonic-gate #define	_FILE_OFFSET_BITS	64
2447c478bd9Sstevel@tonic-gate #endif
2457c478bd9Sstevel@tonic-gate #if	_FILE_OFFSET_BITS - 0 != 64
2467c478bd9Sstevel@tonic-gate #error	"invalid _FILE_OFFSET_BITS value specified"
2477c478bd9Sstevel@tonic-gate #endif
2487c478bd9Sstevel@tonic-gate #else	/* _LP64 */
2497c478bd9Sstevel@tonic-gate #ifndef	_FILE_OFFSET_BITS
2507c478bd9Sstevel@tonic-gate #define	_FILE_OFFSET_BITS	32
2517c478bd9Sstevel@tonic-gate #endif
2527c478bd9Sstevel@tonic-gate #if	_FILE_OFFSET_BITS - 0 != 32 && _FILE_OFFSET_BITS - 0 != 64
2537c478bd9Sstevel@tonic-gate #error	"invalid _FILE_OFFSET_BITS value specified"
2547c478bd9Sstevel@tonic-gate #endif
2557c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * Use of _XOPEN_SOURCE
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  * The following X/Open specifications are supported:
2617c478bd9Sstevel@tonic-gate  *
2627c478bd9Sstevel@tonic-gate  * X/Open Portability Guide, Issue 3 (XPG3)
2637c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 4 (XPG4)
2647c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
2657c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 5 (XPG5)
2667c478bd9Sstevel@tonic-gate  * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
2677c478bd9Sstevel@tonic-gate  *    IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
2682d08521bSGarrett D'Amore  * Open Group Technical Standard, Issue 7 (XPG7), also referred to as
2692d08521bSGarrett D'Amore  *    IEEE Std. 1003.1-2008 and ISO/IEC 9945:2009.
2707c478bd9Sstevel@tonic-gate  *
2717c478bd9Sstevel@tonic-gate  * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
2727c478bd9Sstevel@tonic-gate  * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
2737c478bd9Sstevel@tonic-gate  *     Version 2 (SUSv2)
2747c478bd9Sstevel@tonic-gate  * XPG6 is the result of a merge of the X/Open and POSIX specifications
2757c478bd9Sstevel@tonic-gate  *     and as such is also referred to as IEEE Std. 1003.1-2001 in
2767c478bd9Sstevel@tonic-gate  *     addition to UNIX 03 and SUSv3.
2772d08521bSGarrett D'Amore  * XPG7 is also referred to as UNIX 08 and SUSv4.
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  * When writing a conforming X/Open application, as per the specification
2807c478bd9Sstevel@tonic-gate  * requirements, the appropriate feature test macros must be defined at
281bbf21555SRichard Lowe  * compile time. These are as follows. For more info, see standards(7).
2827c478bd9Sstevel@tonic-gate  *
2837c478bd9Sstevel@tonic-gate  * Feature Test Macro				     Specification
2847c478bd9Sstevel@tonic-gate  * ------------------------------------------------  -------------
2857c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE                                         XPG3
2867c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE && _XOPEN_VERSION = 4                   XPG4
2877c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1           XPG4v2
2887c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE = 500                                   XPG5
2897c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE = 600  (or POSIX_C_SOURCE=200112L)      XPG6
2902d08521bSGarrett D'Amore  * _XOPEN_SOURCE = 700  (or POSIX_C_SOURCE=200809L)      XPG7
2917c478bd9Sstevel@tonic-gate  *
2927c478bd9Sstevel@tonic-gate  * In order to simplify the guards within the headers, the following
2937c478bd9Sstevel@tonic-gate  * implementation private test macros have been created. Applications
2947c478bd9Sstevel@tonic-gate  * must NOT use these private test macros as unexpected results will
2957c478bd9Sstevel@tonic-gate  * occur.
2967c478bd9Sstevel@tonic-gate  *
2977c478bd9Sstevel@tonic-gate  * Note that in general, the use of these private macros is cumulative.
2987c478bd9Sstevel@tonic-gate  * For example, the use of _XPG3 with no other restrictions on the X/Open
2997c478bd9Sstevel@tonic-gate  * namespace will make the symbols visible for XPG3 through XPG6
3007c478bd9Sstevel@tonic-gate  * compilation environments. The use of _XPG4_2 with no other X/Open
3017c478bd9Sstevel@tonic-gate  * namespace restrictions indicates that the symbols were introduced in
3027c478bd9Sstevel@tonic-gate  * XPG4v2 and are therefore visible for XPG4v2 through XPG6 compilation
3037c478bd9Sstevel@tonic-gate  * environments, but not for XPG3 or XPG4 compilation environments.
3047c478bd9Sstevel@tonic-gate  *
3057c478bd9Sstevel@tonic-gate  * _XPG3    X/Open Portability Guide, Issue 3 (XPG3)
3067c478bd9Sstevel@tonic-gate  * _XPG4    X/Open CAE Specification, Issue 4 (XPG4)
3077c478bd9Sstevel@tonic-gate  * _XPG4_2  X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
3087c478bd9Sstevel@tonic-gate  * _XPG5    X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
3097c478bd9Sstevel@tonic-gate  * _XPG6    Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
3102d08521bSGarrett D'Amore  * _XPG7    Open Group Technical Standard, Issue 7 (XPG7/UNIX 08/SUSv4)
3117c478bd9Sstevel@tonic-gate  */
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /* X/Open Portability Guide, Issue 3 */
3147c478bd9Sstevel@tonic-gate #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
3157c478bd9Sstevel@tonic-gate 	(_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
3167c478bd9Sstevel@tonic-gate #define	_XPG3
3177c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 4 */
3187c478bd9Sstevel@tonic-gate #elif	(defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
3197c478bd9Sstevel@tonic-gate #define	_XPG4
3207c478bd9Sstevel@tonic-gate #define	_XPG3
3217c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 4, Version 2 */
3227c478bd9Sstevel@tonic-gate #elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
3237c478bd9Sstevel@tonic-gate #define	_XPG4_2
3247c478bd9Sstevel@tonic-gate #define	_XPG4
3257c478bd9Sstevel@tonic-gate #define	_XPG3
3267c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 5 */
3277c478bd9Sstevel@tonic-gate #elif	(_XOPEN_SOURCE - 0 == 500)
3287c478bd9Sstevel@tonic-gate #define	_XPG5
3297c478bd9Sstevel@tonic-gate #define	_XPG4_2
3307c478bd9Sstevel@tonic-gate #define	_XPG4
3317c478bd9Sstevel@tonic-gate #define	_XPG3
3327c478bd9Sstevel@tonic-gate #undef	_POSIX_C_SOURCE
3337c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE			199506L
3347c478bd9Sstevel@tonic-gate /* Open Group Technical Standard , Issue 6 */
3357c478bd9Sstevel@tonic-gate #elif	(_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
3367c478bd9Sstevel@tonic-gate #define	_XPG6
3377c478bd9Sstevel@tonic-gate #define	_XPG5
3387c478bd9Sstevel@tonic-gate #define	_XPG4_2
3397c478bd9Sstevel@tonic-gate #define	_XPG4
3407c478bd9Sstevel@tonic-gate #define	_XPG3
3417c478bd9Sstevel@tonic-gate #undef	_POSIX_C_SOURCE
3427c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE			200112L
3437c478bd9Sstevel@tonic-gate #undef	_XOPEN_SOURCE
3447c478bd9Sstevel@tonic-gate #define	_XOPEN_SOURCE			600
3452d08521bSGarrett D'Amore 
3462d08521bSGarrett D'Amore /* Open Group Technical Standard, Issue 7 */
3472d08521bSGarrett D'Amore #elif	(_XOPEN_SOURCE - 0 == 700) || (_POSIX_C_SOURCE - 0 == 200809L)
3482d08521bSGarrett D'Amore #define	_XPG7
3492d08521bSGarrett D'Amore #define	_XPG6
3502d08521bSGarrett D'Amore #define	_XPG5
3512d08521bSGarrett D'Amore #define	_XPG4_2
3522d08521bSGarrett D'Amore #define	_XPG4
3532d08521bSGarrett D'Amore #define	_XPG3
3542d08521bSGarrett D'Amore #undef	_POSIX_C_SOURCE
3552d08521bSGarrett D'Amore #define	_POSIX_C_SOURCE			200809L
3562d08521bSGarrett D'Amore #undef	_XOPEN_SOURCE
3572d08521bSGarrett D'Amore #define	_XOPEN_SOURCE			700
3587c478bd9Sstevel@tonic-gate #endif
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate /*
3617c478bd9Sstevel@tonic-gate  * _XOPEN_VERSION is defined by the X/Open specifications and is not
3627c478bd9Sstevel@tonic-gate  * normally defined by the application, except in the case of an XPG4
3637c478bd9Sstevel@tonic-gate  * application.  On the implementation side, _XOPEN_VERSION defined with
3647c478bd9Sstevel@tonic-gate  * the value of 3 indicates an XPG3 application. _XOPEN_VERSION defined
3657c478bd9Sstevel@tonic-gate  * with the value of 4 indicates an XPG4 or XPG4v2 (UNIX 95) application.
3667c478bd9Sstevel@tonic-gate  * _XOPEN_VERSION  defined with a value of 500 indicates an XPG5 (UNIX 98)
3677c478bd9Sstevel@tonic-gate  * application and with a value of 600 indicates an XPG6 (UNIX 03)
3682d08521bSGarrett D'Amore  * application and with a value of 700 indicates an XPG7 (UNIX 08).
3692d08521bSGarrett D'Amore  * The appropriate version is determined by the use of the
3707c478bd9Sstevel@tonic-gate  * feature test macros described earlier.  The value of _XOPEN_VERSION
3717c478bd9Sstevel@tonic-gate  * defaults to 3 otherwise indicating support for XPG3 applications.
3727c478bd9Sstevel@tonic-gate  */
3737c478bd9Sstevel@tonic-gate #ifndef _XOPEN_VERSION
3742d08521bSGarrett D'Amore #if	defined(_XPG7)
3752d08521bSGarrett D'Amore #define	_XOPEN_VERSION 700
3762d08521bSGarrett D'Amore #elif	defined(_XPG6)
3777c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION 600
3787c478bd9Sstevel@tonic-gate #elif defined(_XPG5)
3797c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION 500
3807c478bd9Sstevel@tonic-gate #elif	defined(_XPG4_2)
3817c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION  4
3827c478bd9Sstevel@tonic-gate #else
3837c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION  3
3847c478bd9Sstevel@tonic-gate #endif
3857c478bd9Sstevel@tonic-gate #endif
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate  * ANSI C and ISO 9899:1990 say the type long long doesn't exist in strictly
3897c478bd9Sstevel@tonic-gate  * conforming environments.  ISO 9899:1999 says it does.
3907c478bd9Sstevel@tonic-gate  *
3917c478bd9Sstevel@tonic-gate  * The presence of _LONGLONG_TYPE says "long long exists" which is therefore
3927c478bd9Sstevel@tonic-gate  * defined in all but strictly conforming environments that disallow it.
3937c478bd9Sstevel@tonic-gate  */
3947c478bd9Sstevel@tonic-gate #if !defined(_STDC_C99) && defined(_STRICT_STDC) && !defined(__GNUC__)
3957c478bd9Sstevel@tonic-gate /*
3967c478bd9Sstevel@tonic-gate  * Resist attempts to force the definition of long long in this case.
3977c478bd9Sstevel@tonic-gate  */
3987c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
3997c478bd9Sstevel@tonic-gate #error	"No long long in strictly conforming ANSI C & 1990 ISO C environments"
4007c478bd9Sstevel@tonic-gate #endif
4017c478bd9Sstevel@tonic-gate #else
4027c478bd9Sstevel@tonic-gate #if !defined(_LONGLONG_TYPE)
4037c478bd9Sstevel@tonic-gate #define	_LONGLONG_TYPE
4047c478bd9Sstevel@tonic-gate #endif
4057c478bd9Sstevel@tonic-gate #endif
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  * The following macro defines a value for the ISO C99 restrict
4097c478bd9Sstevel@tonic-gate  * keyword so that _RESTRICT_KYWD resolves to "restrict" if
41010a6478aSRichard PALO  * an ISO C99 compiler is used, "__restrict" for c++ and "" (null string)
41110a6478aSRichard PALO  * if any other compiler is used. This allows for the use of single
41210a6478aSRichard PALO  * prototype declarations regardless of compiler version.
4137c478bd9Sstevel@tonic-gate  */
41410a6478aSRichard PALO #if (defined(__STDC__) && defined(_STDC_C99))
41510a6478aSRichard PALO #ifdef __cplusplus
41610a6478aSRichard PALO #define	_RESTRICT_KYWD	__restrict
41710a6478aSRichard PALO #else
41810a6478aSRichard PALO /*
41910a6478aSRichard PALO  * NOTE: The whitespace between the '#' and 'define' is significant.
42010a6478aSRichard PALO  * It foils gcc's fixincludes from defining a redundant 'restrict'.
42110a6478aSRichard PALO  */
42210a6478aSRichard PALO /* CSTYLED */
4237c478bd9Sstevel@tonic-gate # define	_RESTRICT_KYWD	restrict
42410a6478aSRichard PALO #endif
4257c478bd9Sstevel@tonic-gate #else
4267c478bd9Sstevel@tonic-gate #define	_RESTRICT_KYWD
4277c478bd9Sstevel@tonic-gate #endif
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate /*
430fc2512cfSRobert Mustacchi  * The following macro defines a value for the ISO C11 _Noreturn
431fc2512cfSRobert Mustacchi  * keyword so that _NORETURN_KYWD resolves to "_Noreturn" if
432fc2512cfSRobert Mustacchi  * an ISO C11 compiler is used and "" (null string) if any other
433fc2512cfSRobert Mustacchi  * compiler is used. This allows for the use of single prototype
434fc2512cfSRobert Mustacchi  * declarations regardless of compiler version.
435fc2512cfSRobert Mustacchi  */
436fc2512cfSRobert Mustacchi #if (defined(__STDC__) && defined(_STDC_C11)) && !defined(__cplusplus)
437fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD	_Noreturn
438fc2512cfSRobert Mustacchi #else
439fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD
440fc2512cfSRobert Mustacchi #endif
441fc2512cfSRobert Mustacchi 
44200efb5e1SYuri Pankov /* ISO/IEC 9899:2011 Annex K */
44300efb5e1SYuri Pankov #if defined(__STDC_WANT_LIB_EXT1__)
44400efb5e1SYuri Pankov #if __STDC_WANT_LIB_EXT1__
44500efb5e1SYuri Pankov #define	__EXT1_VISIBLE		1
44600efb5e1SYuri Pankov #else
44700efb5e1SYuri Pankov #define	__EXT1_VISIBLE		0
44800efb5e1SYuri Pankov #endif
449acab0a4fSYuri Pankov #else
450acab0a4fSYuri Pankov #define	__EXT1_VISIBLE		0
45100efb5e1SYuri Pankov #endif /* __STDC_WANT_LIB_EXT1__ */
452fc2512cfSRobert Mustacchi 
453fc2512cfSRobert Mustacchi /*
4547c478bd9Sstevel@tonic-gate  * The following macro indicates header support for the ANSI C++
4557c478bd9Sstevel@tonic-gate  * standard.  The ISO/IEC designation for this is ISO/IEC FDIS 14882.
4567c478bd9Sstevel@tonic-gate  */
4577c478bd9Sstevel@tonic-gate #define	_ISO_CPP_14882_1998
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate /*
4607c478bd9Sstevel@tonic-gate  * The following macro indicates header support for the C99 standard,
4617c478bd9Sstevel@tonic-gate  * ISO/IEC 9899:1999, Programming Languages - C.
4627c478bd9Sstevel@tonic-gate  */
4637c478bd9Sstevel@tonic-gate #define	_ISO_C_9899_1999
4647c478bd9Sstevel@tonic-gate 
4652b6e762cSahl /*
46600efb5e1SYuri Pankov  * The following macro indicates header support for the C11 standard,
467fc2512cfSRobert Mustacchi  * ISO/IEC 9899:2011, Programming Languages - C.
468fc2512cfSRobert Mustacchi  */
469fc2512cfSRobert Mustacchi #define	_ISO_C_9899_2011
470fc2512cfSRobert Mustacchi 
471fc2512cfSRobert Mustacchi /*
47200efb5e1SYuri Pankov  * The following macro indicates header support for the C11 standard,
47300efb5e1SYuri Pankov  * ISO/IEC 9899:2011 Annex K, Programming Languages - C.
47400efb5e1SYuri Pankov  */
47500efb5e1SYuri Pankov #undef	__STDC_LIB_EXT1__
47600efb5e1SYuri Pankov 
47700efb5e1SYuri Pankov /*
4782b6e762cSahl  * The following macro indicates header support for DTrace. The value is an
4792b6e762cSahl  * integer that corresponds to the major version number for DTrace.
4802b6e762cSahl  */
4812b6e762cSahl #define	_DTRACE_VERSION	1
4822b6e762cSahl 
4837c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate #endif
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate #endif	/* _SYS_FEATURE_TESTS_H */
488