4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2013, 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright 2016 Joyent, Inc.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #ifndef _SYS_FEATURE_TESTS_H
31 #define _SYS_FEATURE_TESTS_H
33 #include <sys/ccompile.h>
34 #include <sys/isa_defs.h>
41 * The feature test macros __XOPEN_OR_POSIX, _STRICT_STDC, _STRICT_SYMBOLS,
42 * and _STDC_C99 are Sun implementation specific macros created in order to
43 * compress common standards specified feature test macros for easier reading.
44 * These macros should not be used by the application developer as
45 * unexpected results may occur. Instead, the user should reference
46 * standards(5) for correct usage of the standards feature test macros.
48 * __XOPEN_OR_POSIX Used in cases where a symbol is defined by both
49 * X/Open or POSIX or in the negative, when neither
50 * X/Open or POSIX defines a symbol.
52 * _STRICT_STDC __STDC__ is specified by the C Standards and defined
53 * by the compiler. For Sun compilers the value of
54 * __STDC__ is either 1, 0, or not defined based on the
55 * compilation mode (see cc(1)). When the value of
56 * __STDC__ is 1 and in the absence of any other feature
57 * test macros, the namespace available to the application
58 * is limited to only those symbols defined by the C
59 * Standard. _STRICT_STDC provides a more readable means
60 * of identifying symbols defined by the standard, or in
61 * the negative, symbols that are extensions to the C
62 * Standard. See additional comments for GNU C differences.
64 * _STDC_C99 __STDC_VERSION__ is specified by the C standards and
65 * defined by the compiler and indicates the version of
66 * the C standard. A value of 199901L indicates a
67 * compiler that complies with ISO/IEC 9899:1999, other-
68 * wise known as the C99 standard.
70 * _STDC_C11 Like _STDC_C99 except that the value of __STDC_VERSION__
71 * is 201112L indicating a compiler that compiles with
72 * ISO/IEC 9899:2011, otherwise known as the C11 standard.
74 * _STRICT_SYMBOLS Used in cases where symbol visibility is restricted
75 * by the standards, and the user has not explicitly
76 * relaxed the strictness via __EXTENSIONS__.
80 * XXX: this should go away, but right now it is required to be undefined for
83 #if defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
84 #define __XOPEN_OR_POSIX
88 * ISO/IEC 9899:1990 and it's revisions, ISO/IEC 9899:1999 and ISO/IEC
89 * 99899:2011 specify the following predefined macro name:
91 * __STDC__ The integer constant 1, intended to indicate a conforming
94 * Furthermore, a strictly conforming program shall use only those features
95 * of the language and library specified in these standards. A conforming
96 * implementation shall accept any strictly conforming program.
98 * The GCC project interpretation is that __STDC__ should always be defined
99 * to 1 for compilation modes that accept ANSI C syntax regardless of whether
100 * or not extensions to the C standard are used. Violations of conforming
101 * behavior are conditionally flagged as warnings via the use of the
102 * -pedantic option. In addition to defining __STDC__ to 1, the GNU C
103 * compiler also defines __STRICT_ANSI__ as a means of specifying strictly
104 * conforming environments using the -ansi or -std=<standard> options.
105 * Clang (LLVM) works similarly.
107 * In the absence of any other compiler options, GCC and Clang set the value of
108 * __STDC__ as follows when using the following options:
110 * __STDC__ __STRICT_ANSI__
111 * cc (default) 1 undefined
112 * cc -ansi, -std={c89, c99,...) 1 1
113 * cc -traditional (K&R) undefined undefined
116 #if (__STDC__ - 0 == 1 && defined(__STRICT_ANSI__)) || \
124 * Large file interfaces:
127 * 1 large file-related additions to POSIX
128 * interfaces requested (fseeko, etc.)
129 * _LARGEFILE64_SOURCE
130 * 1 transitional large-file-related interfaces
131 * requested (seek64, stat64, etc.)
133 * The corresponding announcement macros are respectively:
136 * (These are set in <unistd.h>.)
138 * Requesting _LARGEFILE64_SOURCE implies requesting _LARGEFILE_SOURCE as
141 #undef _LARGEFILE64_SOURCE
142 #define _LARGEFILE64_SOURCE 1
143 #undef _LARGEFILE_SOURCE
144 #define _LARGEFILE_SOURCE 1
146 #define _FILE_OFFSET_BITS 64
149 * Use of _XOPEN_SOURCE
151 * The following X/Open specifications are supported:
153 * X/Open Portability Guide, Issue 3 (XPG3)
154 * X/Open CAE Specification, Issue 4 (XPG4)
155 * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
156 * X/Open CAE Specification, Issue 5 (XPG5)
157 * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
158 * IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
159 * Open Group Technical Standard, Issue 7 (XPG7), also referred to as
160 * IEEE Std. 1003.1-2008 and ISO/IEC 9945:2009.
162 * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
163 * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
165 * XPG6 is the result of a merge of the X/Open and POSIX specifications
166 * and as such is also referred to as IEEE Std. 1003.1-2001 in
167 * addition to UNIX 03 and SUSv3.
168 * XPG7 is also referred to as UNIX 08 and SUSv4.
170 * When writing a conforming X/Open application, as per the specification
171 * requirements, the appropriate feature test macros must be defined at
172 * compile time. These are as follows. For more info, see standards(5).
174 * Feature Test Macro Specification
175 * ------------------------------------------------ -------------
177 * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
178 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
179 * _XOPEN_SOURCE = 500 XPG5
180 * _XOPEN_SOURCE = 600 (or POSIX_C_SOURCE=200112L) XPG6
181 * _XOPEN_SOURCE = 700 (or POSIX_C_SOURCE=200809L) XPG7
185 # if (_XOPEN_SOURCE - 0 >= 700)
186 # define __XPG_VISIBLE 700
187 # undef _POSIX_C_SOURCE
188 # define _POSIX_C_SOURCE 200809L
189 # elif (_XOPEN_SOURCE - 0 >= 600)
190 # define __XPG_VISIBLE 600
191 # undef _POSIX_C_SOURCE
192 # define _POSIX_C_SOURCE 200112L
193 # elif (_XOPEN_SOURCE - 0 >= 500)
194 # define __XPG_VISIBLE 500
195 # undef _POSIX_C_SOURCE
196 # define _POSIX_C_SOURCE 199506L
197 # elif (_XOPEN_SOURCE_EXTENDED - 0 == 1)
198 # define __XPG_VISIBLE 420
199 # elif (_XOPEN_VERSION - 0 >= 4)
200 # define __XPG_VISIBLE 400
202 # define __XPG_VISIBLE 300
207 * _POSIX_SOURCE==1 means POSIX.1-1988. Later standards use
213 * 199309L POSIX.1b-1993 (Real Time)
214 * 199506L POSIX.1c-1995 (POSIX Threads)
215 * 200112L POSIX.1-2001 (Austin Group Revision)
216 * 200809L POSIX.1-2008
218 #ifdef _POSIX_C_SOURCE
219 # if (_POSIX_C_SOURCE - 0 >= 200809)
220 # define __POSIX_VISIBLE 200809
221 # elif (_POSIX_C_SOURCE - 0 >= 200112)
222 # define __POSIX_VISIBLE 200112
223 # elif (_POSIX_C_SOURCE - 0 >= 199506)
224 # define __POSIX_VISIBLE 199506
225 # elif (_POSIX_C_SOURCE - 0 >= 199309)
226 # define __POSIX_VISIBLE 199309
227 # elif (_POSIX_C_SOURCE - 0 >= 2)
228 # define __POSIX_VISIBLE 199209
230 # define _POSIX_VISIBLE 199009
232 #elif defined(_POSIX_SOURCE)
233 # define __POSIX_VISIBLE 199808
234 # define __ISO_C_VISIBLE 0
237 #if (__POSIX_VISIBLE - 0 >= 200112)
238 # define __ISO_C_VISIBLE 1999
239 #elif (__POSIX_VISIBLE - 0 >= 199009)
240 # define __ISO_C_VISIBLE 1990
244 * __STDC_VERSION__ and __cplusplus are set by the compiler. They override any
245 * __ISO_C_VISIBLE implied by XPG or POSIX above.
247 #if __STDC_VERSION__ - 0 >= 201112L || __cplusplus - 0 >= 201703
248 #undef __ISO_C_VISIBLE
249 #define __ISO_C_VISIBLE 2011
250 #elif __STDC_VERSION__ - 0 >= 199901L || __cplusplus - 0 >= 201103
251 #undef __ISO_C_VISIBLE
252 #define __ISO_C_VISIBLE 1999
255 /* XXX illumos compat */
256 #if __ISO_C_VISIBLE >= 2011
259 #if __ISO_C_VISIBLE >= 1999
264 * The following macro defines a value for the ISO C99 restrict
265 * keyword so that _RESTRICT_KYWD resolves to "restrict" if
266 * an ISO C99 compiler is used, "__restrict" for c++ and "" (null string)
267 * if any other compiler is used. This allows for the use of single
268 * prototype declarations regardless of compiler version.
270 #if (defined(__STDC__) && defined(_STDC_C99))
272 #define _RESTRICT_KYWD __restrict
275 * NOTE: The whitespace between the '#' and 'define' is significant.
276 * It foils gcc's fixincludes from defining a redundant 'restrict'.
279 # define _RESTRICT_KYWD restrict
282 #define _RESTRICT_KYWD
286 * The following macro defines a value for the ISO C11 _Noreturn
287 * keyword so that _NORETURN_KYWD resolves to "_Noreturn" if
288 * an ISO C11 compiler is used and "" (null string) if any other
289 * compiler is used. This allows for the use of single prototype
290 * declarations regardless of compiler version.
292 #if (defined(__STDC__) && defined(_STDC_C11)) && !defined(__cplusplus)
293 #define _NORETURN_KYWD _Noreturn
295 #define _NORETURN_KYWD
298 /* ISO/IEC 9899:2011 Annex K */
299 #if defined(__STDC_WANT_LIB_EXT1__)
300 #if __STDC_WANT_LIB_EXT1__
301 #define __EXT1_VISIBLE 1
303 #define __EXT1_VISIBLE 0
306 #define __EXT1_VISIBLE 0
307 #endif /* __STDC_WANT_LIB_EXT1__ */
310 * The following macro indicates header support for the ANSI C++
311 * standard. The ISO/IEC designation for this is ISO/IEC FDIS 14882.
313 #define _ISO_CPP_14882_1998
316 * The following macro indicates header support for the C99 standard,
317 * ISO/IEC 9899:1999, Programming Languages - C.
319 #define _ISO_C_9899_1999
322 * The following macro indicates header support for the C11 standard,
323 * ISO/IEC 9899:2011, Programming Languages - C.
325 #define _ISO_C_9899_2011
328 * The following macro indicates header support for the C11 standard,
329 * ISO/IEC 9899:2011 Annex K, Programming Languages - C.
331 #undef __STDC_LIB_EXT1__
334 * The following macro indicates header support for DTrace. The value is an
335 * integer that corresponds to the major version number for DTrace.
337 #define _DTRACE_VERSION 1
340 * The following macro indicates that we are on illumos, and serves to
341 * distinguish us from other SunOS derived systems.
346 * __UNLEASHED_VISIBLE: interfaces that are not part of any standard. Visible
347 * by default, hidden if POSIX or XPG is requested by user.
349 #if !defined(_UNLEASHED_SOURCE) && \
350 (defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
351 # define __UNLEASHED_VISIBLE 0
357 * XXX illumos compat: if we choose the default value here, also define
358 * _XOPEN_SOURCE/_POSIX_C_SOURCE since many headers check for them. also define
359 * __EXTENSIONS__ if XPG was not specified by user.
362 #ifndef __XPG_VISIBLE
363 # define __XPG_VISIBLE 700
364 # define _XOPEN_SOURCE 700
365 # ifndef __EXTENSIONS__
366 # define __EXTENSIONS__
369 #ifndef __POSIX_VISIBLE
370 # define __POSIX_VISIBLE 200809
371 # define _POSIX_C_SOURCE 200809L
373 #ifndef __ISO_C_VISIBLE
374 # define __ISO_C_VISIBLE 2011
377 #ifndef __UNLEASHED_VISIBLE
378 # define __UNLEASHED_VISIBLE 1
381 #if (defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)) && \
382 !defined(__EXTENSIONS__)
383 #define _STRICT_SYMBOLS
387 * XXX for compatibility with headers inherited from illumos.
388 * the _KERNEL check is a bit of a hack; a lot of headers check "#if !_XPG4_2"
389 * when exposing things needed in-tree, so we work around by not setting these
390 * for the kernel, for now.
393 #if (__XPG_VISIBLE >= 700)
396 #if (__XPG_VISIBLE >= 600)
399 #if (__XPG_VISIBLE >= 500)
402 #if (__XPG_VISIBLE >= 420)
405 #if (__XPG_VISIBLE >= 400)
408 #if (__XPG_VISIBLE >= 300)
415 * XXX illumos compat. _XOPEN_VERSION is actually defined by POSIX, but it is
416 * not really useful for anything.
418 #ifndef _XOPEN_VERSION
420 #define _XOPEN_VERSION 700
422 #define _XOPEN_VERSION 600
424 #define _XOPEN_VERSION 500
425 #elif defined(_XPG4_2)
426 #define _XOPEN_VERSION 4
428 #define _XOPEN_VERSION 3
436 #endif /* _SYS_FEATURE_TESTS_H */