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.
25ba3594baSGarrett D'Amore  *
262b6e762cSahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_FEATURE_TESTS_H
317c478bd9Sstevel@tonic-gate #define	_SYS_FEATURE_TESTS_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/ccompile.h>
347c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Values of _POSIX_C_SOURCE
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  *		undefined   not a POSIX compilation
447c478bd9Sstevel@tonic-gate  *		1	    POSIX.1-1990 compilation
457c478bd9Sstevel@tonic-gate  *		2	    POSIX.2-1992 compilation
467c478bd9Sstevel@tonic-gate  *		199309L	    POSIX.1b-1993 compilation (Real Time)
477c478bd9Sstevel@tonic-gate  *		199506L	    POSIX.1c-1995 compilation (POSIX Threads)
487c478bd9Sstevel@tonic-gate  *		200112L	    POSIX.1-2001 compilation (Austin Group Revision)
492d08521bSGarrett D'Amore  *		200809L     POSIX.1-2008 compilation
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
527c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE 1
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
562d08521bSGarrett D'Amore  * The feature test macros __XOPEN_OR_POSIX, _STRICT_STDC, _STRICT_SYMBOLS,
572d08521bSGarrett D'Amore  * and _STDC_C99 are Sun implementation specific macros created in order to
582d08521bSGarrett D'Amore  * compress common standards specified feature test macros for easier reading.
597c478bd9Sstevel@tonic-gate  * These macros should not be used by the application developer as
607c478bd9Sstevel@tonic-gate  * unexpected results may occur. Instead, the user should reference
617c478bd9Sstevel@tonic-gate  * standards(5) for correct usage of the standards feature test macros.
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  * __XOPEN_OR_POSIX     Used in cases where a symbol is defined by both
647c478bd9Sstevel@tonic-gate  *                      X/Open or POSIX or in the negative, when neither
657c478bd9Sstevel@tonic-gate  *                      X/Open or POSIX defines a symbol.
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  * _STRICT_STDC         __STDC__ is specified by the C Standards and defined
687c478bd9Sstevel@tonic-gate  *                      by the compiler. For Sun compilers the value of
697c478bd9Sstevel@tonic-gate  *                      __STDC__ is either 1, 0, or not defined based on the
707c478bd9Sstevel@tonic-gate  *                      compilation mode (see cc(1)). When the value of
717c478bd9Sstevel@tonic-gate  *                      __STDC__ is 1 and in the absence of any other feature
727c478bd9Sstevel@tonic-gate  *                      test macros, the namespace available to the application
737c478bd9Sstevel@tonic-gate  *                      is limited to only those symbols defined by the C
747c478bd9Sstevel@tonic-gate  *                      Standard. _STRICT_STDC provides a more readable means
757c478bd9Sstevel@tonic-gate  *                      of identifying symbols defined by the standard, or in
767c478bd9Sstevel@tonic-gate  *                      the negative, symbols that are extensions to the C
777c478bd9Sstevel@tonic-gate  *                      Standard. See additional comments for GNU C differences.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * _STDC_C99            __STDC_VERSION__ is specified by the C standards and
807c478bd9Sstevel@tonic-gate  *                      defined by the compiler and indicates the version of
817c478bd9Sstevel@tonic-gate  *                      the C standard. A value of 199901L indicates a
827c478bd9Sstevel@tonic-gate  *                      compiler that complies with ISO/IEC 9899:1999, other-
837c478bd9Sstevel@tonic-gate  *                      wise known as the C99 standard.
842d08521bSGarrett D'Amore  *
85fc2512cfSRobert Mustacchi  * _STDC_C11		Like _STDC_C99 except that the value of __STDC_VERSION__
86fc2512cfSRobert Mustacchi  *                      is 201112L indicating a compiler that compiles with
8700efb5e1SYuri Pankov  *                      ISO/IEC 9899:2011, otherwise known as the C11 standard.
88fc2512cfSRobert Mustacchi  *
892d08521bSGarrett D'Amore  * _STRICT_SYMBOLS	Used in cases where symbol visibility is restricted
902d08521bSGarrett D'Amore  *                      by the standards, and the user has not explicitly
912d08521bSGarrett D'Amore  *                      relaxed the strictness via __EXTENSIONS__.
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #if defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
957c478bd9Sstevel@tonic-gate #define	__XOPEN_OR_POSIX
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
99fc2512cfSRobert Mustacchi  * ISO/IEC 9899:1990 and it's revisions, ISO/IEC 9899:1999 and ISO/IEC
100fc2512cfSRobert Mustacchi  * 99899:2011 specify the following predefined macro name:
1017c478bd9Sstevel@tonic-gate  *
1027c478bd9Sstevel@tonic-gate  * __STDC__	The integer constant 1, intended to indicate a conforming
1037c478bd9Sstevel@tonic-gate  *		implementation.
1047c478bd9Sstevel@tonic-gate  *
1057c478bd9Sstevel@tonic-gate  * Furthermore, a strictly conforming program shall use only those features
1067c478bd9Sstevel@tonic-gate  * of the language and library specified in these standards. A conforming
1077c478bd9Sstevel@tonic-gate  * implementation shall accept any strictly conforming program.
1087c478bd9Sstevel@tonic-gate  *
1097c478bd9Sstevel@tonic-gate  * Based on these requirements, Sun's C compiler defines __STDC__ to 1 for
1107c478bd9Sstevel@tonic-gate  * strictly conforming environments and __STDC__ to 0 for environments that
1117c478bd9Sstevel@tonic-gate  * use ANSI C semantics but allow extensions to the C standard. For non-ANSI
1127c478bd9Sstevel@tonic-gate  * C semantics, Sun's C compiler does not define __STDC__.
1137c478bd9Sstevel@tonic-gate  *
1147c478bd9Sstevel@tonic-gate  * The GNU C project interpretation is that __STDC__ should always be defined
1157c478bd9Sstevel@tonic-gate  * to 1 for compilation modes that accept ANSI C syntax regardless of whether
1167c478bd9Sstevel@tonic-gate  * or not extensions to the C standard are used. Violations of conforming
1177c478bd9Sstevel@tonic-gate  * behavior are conditionally flagged as warnings via the use of the
1187c478bd9Sstevel@tonic-gate  * -pedantic option. In addition to defining __STDC__ to 1, the GNU C
1197c478bd9Sstevel@tonic-gate  * compiler also defines __STRICT_ANSI__ as a means of specifying strictly
1207c478bd9Sstevel@tonic-gate  * conforming environments using the -ansi or -std=<standard> options.
1217c478bd9Sstevel@tonic-gate  *
1227c478bd9Sstevel@tonic-gate  * In the absence of any other compiler options, Sun and GNU set the value
1237c478bd9Sstevel@tonic-gate  * of __STDC__ as follows when using the following options:
1247c478bd9Sstevel@tonic-gate  *
1257c478bd9Sstevel@tonic-gate  *				Value of __STDC__  __STRICT_ANSI__
1267c478bd9Sstevel@tonic-gate  *
1277c478bd9Sstevel@tonic-gate  * cc -Xa (default)			0	      undefined
1287c478bd9Sstevel@tonic-gate  * cc -Xt (transitional)		0             undefined
1297c478bd9Sstevel@tonic-gate  * cc -Xc (strictly conforming)		1	      undefined
1307c478bd9Sstevel@tonic-gate  * cc -Xs (K&R C)		    undefined	      undefined
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  * gcc (default)			1	      undefined
13300efb5e1SYuri Pankov  * gcc -ansi, -std={c89, c99,...)	1               defined
1347c478bd9Sstevel@tonic-gate  * gcc -traditional (K&R)	    undefined	      undefined
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  * The default compilation modes for Sun C compilers versus GNU C compilers
1377c478bd9Sstevel@tonic-gate  * results in a differing value for __STDC__ which results in a more
1387c478bd9Sstevel@tonic-gate  * restricted namespace when using Sun compilers. To allow both GNU and Sun
1397c478bd9Sstevel@tonic-gate  * interpretations to peacefully co-exist, we use the following Sun
1407c478bd9Sstevel@tonic-gate  * implementation _STRICT_STDC_ macro:
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #if (__STDC__ - 0 == 1 && !defined(__GNUC__)) || \
1447c478bd9Sstevel@tonic-gate 	(defined(__GNUC__) && defined(__STRICT_ANSI__))
1457c478bd9Sstevel@tonic-gate #define	_STRICT_STDC
1467c478bd9Sstevel@tonic-gate #else
1477c478bd9Sstevel@tonic-gate #undef	_STRICT_STDC
1487c478bd9Sstevel@tonic-gate #endif
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
151fc2512cfSRobert Mustacchi  * Compiler complies with ISO/IEC 9899:1999 or ISO/IEC 9989:2011
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate 
154fc2512cfSRobert Mustacchi #if __STDC_VERSION__ - 0 >= 201112L
155fc2512cfSRobert Mustacchi #define	_STDC_C11
156fc2512cfSRobert Mustacchi #endif
157fc2512cfSRobert Mustacchi 
1587c478bd9Sstevel@tonic-gate #if __STDC_VERSION__ - 0 >= 199901L
1597c478bd9Sstevel@tonic-gate #define	_STDC_C99
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1622d08521bSGarrett D'Amore /*
1632d08521bSGarrett D'Amore  * Use strict symbol visibility.
1642d08521bSGarrett D'Amore  */
1652d08521bSGarrett D'Amore #if (defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)) && \
1662d08521bSGarrett D'Amore 	!defined(__EXTENSIONS__)
1672d08521bSGarrett D'Amore #define	_STRICT_SYMBOLS
1682d08521bSGarrett D'Amore #endif
1692d08521bSGarrett D'Amore 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * Large file interfaces:
1727c478bd9Sstevel@tonic-gate  *
1737c478bd9Sstevel@tonic-gate  *	_LARGEFILE_SOURCE
1747c478bd9Sstevel@tonic-gate  *		1		large file-related additions to POSIX
1757c478bd9Sstevel@tonic-gate  *				interfaces requested (fseeko, etc.)
1767c478bd9Sstevel@tonic-gate  *	_LARGEFILE64_SOURCE
1777c478bd9Sstevel@tonic-gate  *		1		transitional large-file-related interfaces
1787c478bd9Sstevel@tonic-gate  *				requested (seek64, stat64, etc.)
1797c478bd9Sstevel@tonic-gate  *
1807c478bd9Sstevel@tonic-gate  * The corresponding announcement macros are respectively:
1817c478bd9Sstevel@tonic-gate  *	_LFS_LARGEFILE
1827c478bd9Sstevel@tonic-gate  *	_LFS64_LARGEFILE
1837c478bd9Sstevel@tonic-gate  * (These are set in <unistd.h>.)
1847c478bd9Sstevel@tonic-gate  *
1857c478bd9Sstevel@tonic-gate  * Requesting _LARGEFILE64_SOURCE implies requesting _LARGEFILE_SOURCE as
1867c478bd9Sstevel@tonic-gate  * well.
1877c478bd9Sstevel@tonic-gate  *
1887c478bd9Sstevel@tonic-gate  * The large file interfaces are made visible regardless of the initial values
1897c478bd9Sstevel@tonic-gate  * of the feature test macros under certain circumstances:
1907c478bd9Sstevel@tonic-gate  *    -	If no explicit standards-conforming environment is requested (neither
1917c478bd9Sstevel@tonic-gate  *	of _POSIX_SOURCE nor _XOPEN_SOURCE is defined and the value of
1927c478bd9Sstevel@tonic-gate  *	__STDC__ does not imply standards conformance).
1937c478bd9Sstevel@tonic-gate  *    -	Extended system interfaces are explicitly requested (__EXTENSIONS__
19400efb5e1SYuri Pankov  *	is defined).
1957c478bd9Sstevel@tonic-gate  *    -	Access to in-kernel interfaces is requested (_KERNEL or _KMEMUSER is
1967c478bd9Sstevel@tonic-gate  *	defined).  (Note that this dependency is an artifact of the current
1977c478bd9Sstevel@tonic-gate  *	kernel implementation and may change in future releases.)
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate #if	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
2007c478bd9Sstevel@tonic-gate 		defined(_KERNEL) || defined(_KMEMUSER) || \
2017c478bd9Sstevel@tonic-gate 		defined(__EXTENSIONS__)
2027c478bd9Sstevel@tonic-gate #undef	_LARGEFILE64_SOURCE
2037c478bd9Sstevel@tonic-gate #define	_LARGEFILE64_SOURCE	1
2047c478bd9Sstevel@tonic-gate #endif
2057c478bd9Sstevel@tonic-gate #if	_LARGEFILE64_SOURCE - 0 == 1
2067c478bd9Sstevel@tonic-gate #undef	_LARGEFILE_SOURCE
2077c478bd9Sstevel@tonic-gate #define	_LARGEFILE_SOURCE	1
2087c478bd9Sstevel@tonic-gate #endif
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * Large file compilation environment control:
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  * The setting of _FILE_OFFSET_BITS controls the size of various file-related
2147c478bd9Sstevel@tonic-gate  * types and governs the mapping between file-related source function symbol
2157c478bd9Sstevel@tonic-gate  * names and the corresponding binary entry points.
2167c478bd9Sstevel@tonic-gate  *
2177c478bd9Sstevel@tonic-gate  * In the 32-bit environment, the default value is 32; if not set, set it to
2187c478bd9Sstevel@tonic-gate  * the default here, to simplify tests in other headers.
2197c478bd9Sstevel@tonic-gate  *
2207c478bd9Sstevel@tonic-gate  * In the 64-bit compilation environment, the only value allowed is 64.
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate #if defined(_LP64)
2237c478bd9Sstevel@tonic-gate #ifndef _FILE_OFFSET_BITS
2247c478bd9Sstevel@tonic-gate #define	_FILE_OFFSET_BITS	64
2257c478bd9Sstevel@tonic-gate #endif
2267c478bd9Sstevel@tonic-gate #if	_FILE_OFFSET_BITS - 0 != 64
2277c478bd9Sstevel@tonic-gate #error	"invalid _FILE_OFFSET_BITS value specified"
2287c478bd9Sstevel@tonic-gate #endif
2297c478bd9Sstevel@tonic-gate #else	/* _LP64 */
2307c478bd9Sstevel@tonic-gate #ifndef	_FILE_OFFSET_BITS
2317c478bd9Sstevel@tonic-gate #define	_FILE_OFFSET_BITS	32
2327c478bd9Sstevel@tonic-gate #endif
2337c478bd9Sstevel@tonic-gate #if	_FILE_OFFSET_BITS - 0 != 32 && _FILE_OFFSET_BITS - 0 != 64
2347c478bd9Sstevel@tonic-gate #error	"invalid _FILE_OFFSET_BITS value specified"
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate #endif	/* _LP64 */
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate /*
2397c478bd9Sstevel@tonic-gate  * Use of _XOPEN_SOURCE
2407c478bd9Sstevel@tonic-gate  *
2417c478bd9Sstevel@tonic-gate  * The following X/Open specifications are supported:
2427c478bd9Sstevel@tonic-gate  *
2437c478bd9Sstevel@tonic-gate  * X/Open Portability Guide, Issue 3 (XPG3)
2447c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 4 (XPG4)
2457c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
2467c478bd9Sstevel@tonic-gate  * X/Open CAE Specification, Issue 5 (XPG5)
2477c478bd9Sstevel@tonic-gate  * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
2487c478bd9Sstevel@tonic-gate  *    IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
2492d08521bSGarrett D'Amore  * Open Group Technical Standard, Issue 7 (XPG7), also referred to as
2502d08521bSGarrett D'Amore  *    IEEE Std. 1003.1-2008 and ISO/IEC 9945:2009.
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
2537c478bd9Sstevel@tonic-gate  * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
2547c478bd9Sstevel@tonic-gate  *     Version 2 (SUSv2)
2557c478bd9Sstevel@tonic-gate  * XPG6 is the result of a merge of the X/Open and POSIX specifications
2567c478bd9Sstevel@tonic-gate  *     and as such is also referred to as IEEE Std. 1003.1-2001 in
2577c478bd9Sstevel@tonic-gate  *     addition to UNIX 03 and SUSv3.
2582d08521bSGarrett D'Amore  * XPG7 is also referred to as UNIX 08 and SUSv4.
2597c478bd9Sstevel@tonic-gate  *
2607c478bd9Sstevel@tonic-gate  * When writing a conforming X/Open application, as per the specification
2617c478bd9Sstevel@tonic-gate  * requirements, the appropriate feature test macros must be defined at
2627c478bd9Sstevel@tonic-gate  * compile time. These are as follows. For more info, see standards(5).
2637c478bd9Sstevel@tonic-gate  *
2647c478bd9Sstevel@tonic-gate  * Feature Test Macro				     Specification
2657c478bd9Sstevel@tonic-gate  * ------------------------------------------------  -------------
2667c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE                                         XPG3
2677c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE && _XOPEN_VERSION = 4                   XPG4
2687c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1           XPG4v2
2697c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE = 500                                   XPG5
2707c478bd9Sstevel@tonic-gate  * _XOPEN_SOURCE = 600  (or POSIX_C_SOURCE=200112L)      XPG6
2712d08521bSGarrett D'Amore  * _XOPEN_SOURCE = 700  (or POSIX_C_SOURCE=200809L)      XPG7
2727c478bd9Sstevel@tonic-gate  *
2737c478bd9Sstevel@tonic-gate  * In order to simplify the guards within the headers, the following
2747c478bd9Sstevel@tonic-gate  * implementation private test macros have been created. Applications
2757c478bd9Sstevel@tonic-gate  * must NOT use these private test macros as unexpected results will
2767c478bd9Sstevel@tonic-gate  * occur.
2777c478bd9Sstevel@tonic-gate  *
2787c478bd9Sstevel@tonic-gate  * Note that in general, the use of these private macros is cumulative.
2797c478bd9Sstevel@tonic-gate  * For example, the use of _XPG3 with no other restrictions on the X/Open
2807c478bd9Sstevel@tonic-gate  * namespace will make the symbols visible for XPG3 through XPG6
2817c478bd9Sstevel@tonic-gate  * compilation environments. The use of _XPG4_2 with no other X/Open
2827c478bd9Sstevel@tonic-gate  * namespace restrictions indicates that the symbols were introduced in
2837c478bd9Sstevel@tonic-gate  * XPG4v2 and are therefore visible for XPG4v2 through XPG6 compilation
2847c478bd9Sstevel@tonic-gate  * environments, but not for XPG3 or XPG4 compilation environments.
2857c478bd9Sstevel@tonic-gate  *
2867c478bd9Sstevel@tonic-gate  * _XPG3    X/Open Portability Guide, Issue 3 (XPG3)
2877c478bd9Sstevel@tonic-gate  * _XPG4    X/Open CAE Specification, Issue 4 (XPG4)
2887c478bd9Sstevel@tonic-gate  * _XPG4_2  X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
2897c478bd9Sstevel@tonic-gate  * _XPG5    X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
2907c478bd9Sstevel@tonic-gate  * _XPG6    Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
2912d08521bSGarrett D'Amore  * _XPG7    Open Group Technical Standard, Issue 7 (XPG7/UNIX 08/SUSv4)
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /* X/Open Portability Guide, Issue 3 */
2957c478bd9Sstevel@tonic-gate #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
2967c478bd9Sstevel@tonic-gate 	(_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
2977c478bd9Sstevel@tonic-gate #define	_XPG3
2987c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 4 */
2997c478bd9Sstevel@tonic-gate #elif	(defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
3007c478bd9Sstevel@tonic-gate #define	_XPG4
3017c478bd9Sstevel@tonic-gate #define	_XPG3
3027c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 4, Version 2 */
3037c478bd9Sstevel@tonic-gate #elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
3047c478bd9Sstevel@tonic-gate #define	_XPG4_2
3057c478bd9Sstevel@tonic-gate #define	_XPG4
3067c478bd9Sstevel@tonic-gate #define	_XPG3
3077c478bd9Sstevel@tonic-gate /* X/Open CAE Specification, Issue 5 */
3087c478bd9Sstevel@tonic-gate #elif	(_XOPEN_SOURCE - 0 == 500)
3097c478bd9Sstevel@tonic-gate #define	_XPG5
3107c478bd9Sstevel@tonic-gate #define	_XPG4_2
3117c478bd9Sstevel@tonic-gate #define	_XPG4
3127c478bd9Sstevel@tonic-gate #define	_XPG3
3137c478bd9Sstevel@tonic-gate #undef	_POSIX_C_SOURCE
3147c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE			199506L
3157c478bd9Sstevel@tonic-gate /* Open Group Technical Standard , Issue 6 */
3167c478bd9Sstevel@tonic-gate #elif	(_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
3177c478bd9Sstevel@tonic-gate #define	_XPG6
3187c478bd9Sstevel@tonic-gate #define	_XPG5
3197c478bd9Sstevel@tonic-gate #define	_XPG4_2
3207c478bd9Sstevel@tonic-gate #define	_XPG4
3217c478bd9Sstevel@tonic-gate #define	_XPG3
3227c478bd9Sstevel@tonic-gate #undef	_POSIX_C_SOURCE
3237c478bd9Sstevel@tonic-gate #define	_POSIX_C_SOURCE			200112L
3247c478bd9Sstevel@tonic-gate #undef	_XOPEN_SOURCE
3257c478bd9Sstevel@tonic-gate #define	_XOPEN_SOURCE			600
3262d08521bSGarrett D'Amore 
3272d08521bSGarrett D'Amore /* Open Group Technical Standard, Issue 7 */
3282d08521bSGarrett D'Amore #elif	(_XOPEN_SOURCE - 0 == 700) || (_POSIX_C_SOURCE - 0 == 200809L)
3292d08521bSGarrett D'Amore #define	_XPG7
3302d08521bSGarrett D'Amore #define	_XPG6
3312d08521bSGarrett D'Amore #define	_XPG5
3322d08521bSGarrett D'Amore #define	_XPG4_2
3332d08521bSGarrett D'Amore #define	_XPG4
3342d08521bSGarrett D'Amore #define	_XPG3
3352d08521bSGarrett D'Amore #undef	_POSIX_C_SOURCE
3362d08521bSGarrett D'Amore #define	_POSIX_C_SOURCE			200809L
3372d08521bSGarrett D'Amore #undef	_XOPEN_SOURCE
3382d08521bSGarrett D'Amore #define	_XOPEN_SOURCE			700
3397c478bd9Sstevel@tonic-gate #endif
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate  * _XOPEN_VERSION is defined by the X/Open specifications and is not
3437c478bd9Sstevel@tonic-gate  * normally defined by the application, except in the case of an XPG4
3447c478bd9Sstevel@tonic-gate  * application.  On the implementation side, _XOPEN_VERSION defined with
3457c478bd9Sstevel@tonic-gate  * the value of 3 indicates an XPG3 application. _XOPEN_VERSION defined
3467c478bd9Sstevel@tonic-gate  * with the value of 4 indicates an XPG4 or XPG4v2 (UNIX 95) application.
3477c478bd9Sstevel@tonic-gate  * _XOPEN_VERSION  defined with a value of 500 indicates an XPG5 (UNIX 98)
3487c478bd9Sstevel@tonic-gate  * application and with a value of 600 indicates an XPG6 (UNIX 03)
3492d08521bSGarrett D'Amore  * application and with a value of 700 indicates an XPG7 (UNIX 08).
3502d08521bSGarrett D'Amore  * The appropriate version is determined by the use of the
3517c478bd9Sstevel@tonic-gate  * feature test macros described earlier.  The value of _XOPEN_VERSION
3527c478bd9Sstevel@tonic-gate  * defaults to 3 otherwise indicating support for XPG3 applications.
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate #ifndef _XOPEN_VERSION
3552d08521bSGarrett D'Amore #if	defined(_XPG7)
3562d08521bSGarrett D'Amore #define	_XOPEN_VERSION 700
3572d08521bSGarrett D'Amore #elif	defined(_XPG6)
3587c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION 600
3597c478bd9Sstevel@tonic-gate #elif defined(_XPG5)
3607c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION 500
3617c478bd9Sstevel@tonic-gate #elif	defined(_XPG4_2)
3627c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION  4
3637c478bd9Sstevel@tonic-gate #else
3647c478bd9Sstevel@tonic-gate #define	_XOPEN_VERSION  3
3657c478bd9Sstevel@tonic-gate #endif
3667c478bd9Sstevel@tonic-gate #endif
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate /*
3697c478bd9Sstevel@tonic-gate  * ANSI C and ISO 9899:1990 say the type long long doesn't exist in strictly
3707c478bd9Sstevel@tonic-gate  * conforming environments.  ISO 9899:1999 says it does.
3717c478bd9Sstevel@tonic-gate  *
3727c478bd9Sstevel@tonic-gate  * The presence of _LONGLONG_TYPE says "long long exists" which is therefore
3737c478bd9Sstevel@tonic-gate  * defined in all but strictly conforming environments that disallow it.
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate #if !defined(_STDC_C99) && defined(_STRICT_STDC) && !defined(__GNUC__)
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate  * Resist attempts to force the definition of long long in this case.
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate #if defined(_LONGLONG_TYPE)
3807c478bd9Sstevel@tonic-gate #error	"No long long in strictly conforming ANSI C & 1990 ISO C environments"
3817c478bd9Sstevel@tonic-gate #endif
3827c478bd9Sstevel@tonic-gate #else
3837c478bd9Sstevel@tonic-gate #if !defined(_LONGLONG_TYPE)
3847c478bd9Sstevel@tonic-gate #define	_LONGLONG_TYPE
3857c478bd9Sstevel@tonic-gate #endif
3867c478bd9Sstevel@tonic-gate #endif
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate  * The following macro defines a value for the ISO C99 restrict
3907c478bd9Sstevel@tonic-gate  * keyword so that _RESTRICT_KYWD resolves to "restrict" if
39110a6478aSRichard PALO  * an ISO C99 compiler is used, "__restrict" for c++ and "" (null string)
39210a6478aSRichard PALO  * if any other compiler is used. This allows for the use of single
39310a6478aSRichard PALO  * prototype declarations regardless of compiler version.
3947c478bd9Sstevel@tonic-gate  */
39510a6478aSRichard PALO #if (defined(__STDC__) && defined(_STDC_C99))
39610a6478aSRichard PALO #ifdef __cplusplus
39710a6478aSRichard PALO #define	_RESTRICT_KYWD	__restrict
39810a6478aSRichard PALO #else
39910a6478aSRichard PALO /*
40010a6478aSRichard PALO  * NOTE: The whitespace between the '#' and 'define' is significant.
40110a6478aSRichard PALO  * It foils gcc's fixincludes from defining a redundant 'restrict'.
40210a6478aSRichard PALO  */
40310a6478aSRichard PALO /* CSTYLED */
40410a6478aSRichard PALO # define	_RESTRICT_KYWD	restrict
40510a6478aSRichard PALO #endif
4067c478bd9Sstevel@tonic-gate #else
4077c478bd9Sstevel@tonic-gate #define	_RESTRICT_KYWD
4087c478bd9Sstevel@tonic-gate #endif
4097c478bd9Sstevel@tonic-gate 
410fc2512cfSRobert Mustacchi /*
411fc2512cfSRobert Mustacchi  * The following macro defines a value for the ISO C11 _Noreturn
412fc2512cfSRobert Mustacchi  * keyword so that _NORETURN_KYWD resolves to "_Noreturn" if
413fc2512cfSRobert Mustacchi  * an ISO C11 compiler is used and "" (null string) if any other
414fc2512cfSRobert Mustacchi  * compiler is used. This allows for the use of single prototype
415fc2512cfSRobert Mustacchi  * declarations regardless of compiler version.
416fc2512cfSRobert Mustacchi  */
417fc2512cfSRobert Mustacchi #if (defined(__STDC__) && defined(_STDC_C11)) && !defined(__cplusplus)
418fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD	_Noreturn
419fc2512cfSRobert Mustacchi #else
420fc2512cfSRobert Mustacchi #define	_NORETURN_KYWD
421fc2512cfSRobert Mustacchi #endif
422fc2512cfSRobert Mustacchi 
42300efb5e1SYuri Pankov /* ISO/IEC 9899:2011 Annex K */
42400efb5e1SYuri Pankov #if defined(__STDC_WANT_LIB_EXT1__)
42500efb5e1SYuri Pankov #if __STDC_WANT_LIB_EXT1__
42600efb5e1SYuri Pankov #define	__EXT1_VISIBLE		1
42700efb5e1SYuri Pankov #else
42800efb5e1SYuri Pankov #define	__EXT1_VISIBLE		0
42900efb5e1SYuri Pankov #endif
430*acab0a4fSYuri Pankov #else
431*acab0a4fSYuri Pankov #define	__EXT1_VISIBLE		0
43200efb5e1SYuri Pankov #endif /* __STDC_WANT_LIB_EXT1__ */
433fc2512cfSRobert Mustacchi 
4347c478bd9Sstevel@tonic-gate /*
4357c478bd9Sstevel@tonic-gate  * The following macro indicates header support for the ANSI C++
4367c478bd9Sstevel@tonic-gate  * standard.  The ISO/IEC designation for this is ISO/IEC FDIS 14882.
4377c478bd9Sstevel@tonic-gate  */
4387c478bd9Sstevel@tonic-gate #define	_ISO_CPP_14882_1998
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate /*
4417c478bd9Sstevel@tonic-gate  * The following macro indicates header support for the C99 standard,
4427c478bd9Sstevel@tonic-gate  * ISO/IEC 9899:1999, Programming Languages - C.
4437c478bd9Sstevel@tonic-gate  */
4447c478bd9Sstevel@tonic-gate #define	_ISO_C_9899_1999
4457c478bd9Sstevel@tonic-gate 
446fc2512cfSRobert Mustacchi /*
44700efb5e1SYuri Pankov  * The following macro indicates header support for the C11 standard,
448fc2512cfSRobert Mustacchi  * ISO/IEC 9899:2011, Programming Languages - C.
449fc2512cfSRobert Mustacchi  */
450fc2512cfSRobert Mustacchi #define	_ISO_C_9899_2011
451fc2512cfSRobert Mustacchi 
45200efb5e1SYuri Pankov /*
45300efb5e1SYuri Pankov  * The following macro indicates header support for the C11 standard,
45400efb5e1SYuri Pankov  * ISO/IEC 9899:2011 Annex K, Programming Languages - C.
45500efb5e1SYuri Pankov  */
45600efb5e1SYuri Pankov #undef	__STDC_LIB_EXT1__
45700efb5e1SYuri Pankov 
4582b6e762cSahl /*
4592b6e762cSahl  * The following macro indicates header support for DTrace. The value is an
4602b6e762cSahl  * integer that corresponds to the major version number for DTrace.
4612b6e762cSahl  */
4622b6e762cSahl #define	_DTRACE_VERSION	1
4632b6e762cSahl 
4647c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate #endif
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate #endif	/* _SYS_FEATURE_TESTS_H */
469