autofs: disable by default
[unleashed.git] / include / sys / feature_tests.h
blobc4764283dfcabd07f8b33ec21b39582edda0285b
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
41 * Values of _POSIX_C_SOURCE
43 * undefined not a POSIX compilation
44 * 1 POSIX.1-1990 compilation
45 * 2 POSIX.2-1992 compilation
46 * 199309L POSIX.1b-1993 compilation (Real Time)
47 * 199506L POSIX.1c-1995 compilation (POSIX Threads)
48 * 200112L POSIX.1-2001 compilation (Austin Group Revision)
49 * 200809L POSIX.1-2008 compilation
51 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
52 #define _POSIX_C_SOURCE 1
53 #endif
56 * The feature test macros __XOPEN_OR_POSIX, _STRICT_STDC, _STRICT_SYMBOLS,
57 * and _STDC_C99 are Sun implementation specific macros created in order to
58 * compress common standards specified feature test macros for easier reading.
59 * These macros should not be used by the application developer as
60 * unexpected results may occur. Instead, the user should reference
61 * standards(5) for correct usage of the standards feature test macros.
63 * __XOPEN_OR_POSIX Used in cases where a symbol is defined by both
64 * X/Open or POSIX or in the negative, when neither
65 * X/Open or POSIX defines a symbol.
67 * _STRICT_STDC __STDC__ is specified by the C Standards and defined
68 * by the compiler. For Sun compilers the value of
69 * __STDC__ is either 1, 0, or not defined based on the
70 * compilation mode (see cc(1)). When the value of
71 * __STDC__ is 1 and in the absence of any other feature
72 * test macros, the namespace available to the application
73 * is limited to only those symbols defined by the C
74 * Standard. _STRICT_STDC provides a more readable means
75 * of identifying symbols defined by the standard, or in
76 * the negative, symbols that are extensions to the C
77 * Standard. See additional comments for GNU C differences.
79 * _STDC_C99 __STDC_VERSION__ is specified by the C standards and
80 * defined by the compiler and indicates the version of
81 * the C standard. A value of 199901L indicates a
82 * compiler that complies with ISO/IEC 9899:1999, other-
83 * wise known as the C99 standard.
85 * _STDC_C11 Like _STDC_C99 except that the value of __STDC_VERSION__
86 * is 201112L indicating a compiler that compiles with
87 * ISO/IEXC 9899:2011, otherwise known as the C11 standard.
89 * _STRICT_SYMBOLS Used in cases where symbol visibility is restricted
90 * by the standards, and the user has not explicitly
91 * relaxed the strictness via __EXTENSIONS__.
94 #if defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
95 #define __XOPEN_OR_POSIX
96 #endif
99 * ISO/IEC 9899:1990 and it's revisions, ISO/IEC 9899:1999 and ISO/IEC
100 * 99899:2011 specify the following predefined macro name:
102 * __STDC__ The integer constant 1, intended to indicate a conforming
103 * implementation.
105 * Furthermore, a strictly conforming program shall use only those features
106 * of the language and library specified in these standards. A conforming
107 * implementation shall accept any strictly conforming program.
109 * Based on these requirements, Sun's C compiler defines __STDC__ to 1 for
110 * strictly conforming environments and __STDC__ to 0 for environments that
111 * use ANSI C semantics but allow extensions to the C standard. For non-ANSI
112 * C semantics, Sun's C compiler does not define __STDC__.
114 * The GNU C project interpretation is that __STDC__ should always be defined
115 * to 1 for compilation modes that accept ANSI C syntax regardless of whether
116 * or not extensions to the C standard are used. Violations of conforming
117 * behavior are conditionally flagged as warnings via the use of the
118 * -pedantic option. In addition to defining __STDC__ to 1, the GNU C
119 * compiler also defines __STRICT_ANSI__ as a means of specifying strictly
120 * conforming environments using the -ansi or -std=<standard> options.
122 * In the absence of any other compiler options, Sun and GNU set the value
123 * of __STDC__ as follows when using the following options:
125 * Value of __STDC__ __STRICT_ANSI__
127 * cc -Xa (default) 0 undefined
128 * cc -Xt (transitional) 0 undefined
129 * cc -Xc (strictly conforming) 1 undefined
130 * cc -Xs (K&R C) undefined undefined
132 * gcc (default) 1 undefined
133 * gcc -ansi, -std={c89, c99,...) 1 defined
134 * gcc -traditional (K&R) undefined undefined
136 * The default compilation modes for Sun C compilers versus GNU C compilers
137 * results in a differing value for __STDC__ which results in a more
138 * restricted namespace when using Sun compilers. To allow both GNU and Sun
139 * interpretations to peacefully co-exist, we use the following Sun
140 * implementation _STRICT_STDC_ macro:
143 #if (__STDC__ - 0 == 1 && !defined(__GNUC__)) || \
144 (defined(__GNUC__) && defined(__STRICT_ANSI__)) || \
145 defined(_ASM)
146 #define _STRICT_STDC
147 #else
148 #undef _STRICT_STDC
149 #endif
152 * Compiler complies with ISO/IEC 9899:1999 or ISO/IEC 9989:2011
155 #if __STDC_VERSION__ - 0 >= 201112L
156 #define _STDC_C11
157 #endif
159 #if __STDC_VERSION__ - 0 >= 199901L
160 #define _STDC_C99
161 #endif
164 * Use strict symbol visibility.
166 #if (defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)) && \
167 !defined(__EXTENSIONS__)
168 #define _STRICT_SYMBOLS
169 #endif
172 * Large file interfaces:
174 * _LARGEFILE_SOURCE
175 * 1 large file-related additions to POSIX
176 * interfaces requested (fseeko, etc.)
177 * _LARGEFILE64_SOURCE
178 * 1 transitional large-file-related interfaces
179 * requested (seek64, stat64, etc.)
181 * The corresponding announcement macros are respectively:
182 * _LFS_LARGEFILE
183 * _LFS64_LARGEFILE
184 * (These are set in <unistd.h>.)
186 * Requesting _LARGEFILE64_SOURCE implies requesting _LARGEFILE_SOURCE as
187 * well.
189 * The large file interfaces are made visible regardless of the initial values
190 * of the feature test macros under certain circumstances:
191 * - If no explicit standards-conforming environment is requested (neither
192 * of _POSIX_SOURCE nor _XOPEN_SOURCE is defined and the value of
193 * __STDC__ does not imply standards conformance).
194 * - Extended system interfaces are explicitly requested (__EXTENSIONS__
195 * is defined).
196 * - Access to in-kernel interfaces is requested (_KERNEL or _KMEMUSER is
197 * defined). (Note that this dependency is an artifact of the current
198 * kernel implementation and may change in future releases.)
200 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
201 defined(_KERNEL) || defined(_KMEMUSER) || \
202 defined(__EXTENSIONS__)
203 #undef _LARGEFILE64_SOURCE
204 #define _LARGEFILE64_SOURCE 1
205 #endif
206 #if _LARGEFILE64_SOURCE - 0 == 1
207 #undef _LARGEFILE_SOURCE
208 #define _LARGEFILE_SOURCE 1
209 #endif
212 * Large file compilation environment control:
214 * The setting of _FILE_OFFSET_BITS controls the size of various file-related
215 * types and governs the mapping between file-related source function symbol
216 * names and the corresponding binary entry points.
218 * In the 32-bit environment, the default value is 32; if not set, set it to
219 * the default here, to simplify tests in other headers.
221 * In the 64-bit compilation environment, the only value allowed is 64.
223 #if defined(_LP64)
224 #ifndef _FILE_OFFSET_BITS
225 #define _FILE_OFFSET_BITS 64
226 #endif
227 #if _FILE_OFFSET_BITS - 0 != 64
228 #error "invalid _FILE_OFFSET_BITS value specified"
229 #endif
230 #else /* _LP64 */
231 #ifndef _FILE_OFFSET_BITS
232 #define _FILE_OFFSET_BITS 32
233 #endif
234 #if _FILE_OFFSET_BITS - 0 != 32 && _FILE_OFFSET_BITS - 0 != 64
235 #error "invalid _FILE_OFFSET_BITS value specified"
236 #endif
237 #endif /* _LP64 */
240 * Use of _XOPEN_SOURCE
242 * The following X/Open specifications are supported:
244 * X/Open Portability Guide, Issue 3 (XPG3)
245 * X/Open CAE Specification, Issue 4 (XPG4)
246 * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
247 * X/Open CAE Specification, Issue 5 (XPG5)
248 * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
249 * IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
250 * Open Group Technical Standard, Issue 7 (XPG7), also referred to as
251 * IEEE Std. 1003.1-2008 and ISO/IEC 9945:2009.
253 * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
254 * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
255 * Version 2 (SUSv2)
256 * XPG6 is the result of a merge of the X/Open and POSIX specifications
257 * and as such is also referred to as IEEE Std. 1003.1-2001 in
258 * addition to UNIX 03 and SUSv3.
259 * XPG7 is also referred to as UNIX 08 and SUSv4.
261 * When writing a conforming X/Open application, as per the specification
262 * requirements, the appropriate feature test macros must be defined at
263 * compile time. These are as follows. For more info, see standards(5).
265 * Feature Test Macro Specification
266 * ------------------------------------------------ -------------
267 * _XOPEN_SOURCE XPG3
268 * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
269 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
270 * _XOPEN_SOURCE = 500 XPG5
271 * _XOPEN_SOURCE = 600 (or POSIX_C_SOURCE=200112L) XPG6
272 * _XOPEN_SOURCE = 700 (or POSIX_C_SOURCE=200809L) XPG7
274 * In order to simplify the guards within the headers, the following
275 * implementation private test macros have been created. Applications
276 * must NOT use these private test macros as unexpected results will
277 * occur.
279 * Note that in general, the use of these private macros is cumulative.
280 * For example, the use of _XPG3 with no other restrictions on the X/Open
281 * namespace will make the symbols visible for XPG3 through XPG6
282 * compilation environments. The use of _XPG4_2 with no other X/Open
283 * namespace restrictions indicates that the symbols were introduced in
284 * XPG4v2 and are therefore visible for XPG4v2 through XPG6 compilation
285 * environments, but not for XPG3 or XPG4 compilation environments.
287 * _XPG3 X/Open Portability Guide, Issue 3 (XPG3)
288 * _XPG4 X/Open CAE Specification, Issue 4 (XPG4)
289 * _XPG4_2 X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
290 * _XPG5 X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
291 * _XPG6 Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
292 * _XPG7 Open Group Technical Standard, Issue 7 (XPG7/UNIX 08/SUSv4)
295 /* X/Open Portability Guide, Issue 3 */
296 #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
297 (_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
298 #define _XPG3
299 /* X/Open CAE Specification, Issue 4 */
300 #elif (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
301 #define _XPG4
302 #define _XPG3
303 /* X/Open CAE Specification, Issue 4, Version 2 */
304 #elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
305 #define _XPG4_2
306 #define _XPG4
307 #define _XPG3
308 /* X/Open CAE Specification, Issue 5 */
309 #elif (_XOPEN_SOURCE - 0 == 500)
310 #define _XPG5
311 #define _XPG4_2
312 #define _XPG4
313 #define _XPG3
314 #undef _POSIX_C_SOURCE
315 #define _POSIX_C_SOURCE 199506L
316 /* Open Group Technical Standard , Issue 6 */
317 #elif (_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
318 #define _XPG6
319 #define _XPG5
320 #define _XPG4_2
321 #define _XPG4
322 #define _XPG3
323 #undef _POSIX_C_SOURCE
324 #define _POSIX_C_SOURCE 200112L
325 #undef _XOPEN_SOURCE
326 #define _XOPEN_SOURCE 600
328 /* Open Group Technical Standard, Issue 7 */
329 #elif (_XOPEN_SOURCE - 0 == 700) || (_POSIX_C_SOURCE - 0 == 200809L)
330 #define _XPG7
331 #define _XPG6
332 #define _XPG5
333 #define _XPG4_2
334 #define _XPG4
335 #define _XPG3
336 #undef _POSIX_C_SOURCE
337 #define _POSIX_C_SOURCE 200809L
338 #undef _XOPEN_SOURCE
339 #define _XOPEN_SOURCE 700
340 #endif
343 * _XOPEN_VERSION is defined by the X/Open specifications and is not
344 * normally defined by the application, except in the case of an XPG4
345 * application. On the implementation side, _XOPEN_VERSION defined with
346 * the value of 3 indicates an XPG3 application. _XOPEN_VERSION defined
347 * with the value of 4 indicates an XPG4 or XPG4v2 (UNIX 95) application.
348 * _XOPEN_VERSION defined with a value of 500 indicates an XPG5 (UNIX 98)
349 * application and with a value of 600 indicates an XPG6 (UNIX 03)
350 * application and with a value of 700 indicates an XPG7 (UNIX 08).
351 * The appropriate version is determined by the use of the
352 * feature test macros described earlier. The value of _XOPEN_VERSION
353 * defaults to 3 otherwise indicating support for XPG3 applications.
355 #ifndef _XOPEN_VERSION
356 #if defined(_XPG7)
357 #define _XOPEN_VERSION 700
358 #elif defined(_XPG6)
359 #define _XOPEN_VERSION 600
360 #elif defined(_XPG5)
361 #define _XOPEN_VERSION 500
362 #elif defined(_XPG4_2)
363 #define _XOPEN_VERSION 4
364 #else
365 #define _XOPEN_VERSION 3
366 #endif
367 #endif
370 * ANSI C and ISO 9899:1990 say the type long long doesn't exist in strictly
371 * conforming environments. ISO 9899:1999 says it does.
373 * The presence of _LONGLONG_TYPE says "long long exists" which is therefore
374 * defined in all but strictly conforming environments that disallow it.
376 #if !defined(_STDC_C99) && defined(_STRICT_STDC) && !defined(__GNUC__)
378 * Resist attempts to force the definition of long long in this case.
380 #if defined(_LONGLONG_TYPE)
381 #error "No long long in strictly conforming ANSI C & 1990 ISO C environments"
382 #endif
383 #else
384 #if !defined(_LONGLONG_TYPE)
385 #define _LONGLONG_TYPE
386 #endif
387 #endif
390 * It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
391 * using c99. The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
392 * and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
393 * or a POSIX.1-2001 application with anything other than a c99 or later
394 * compiler. Therefore, we force an error in both cases.
396 #if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
397 #error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
398 and pre-2001 POSIX applications"
399 #elif !defined(_STDC_C99) && \
400 (defined(__XOPEN_OR_POSIX) && defined(_XPG6))
401 #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
402 require the use of c99"
403 #endif
406 * The following macro defines a value for the ISO C99 restrict
407 * keyword so that _RESTRICT_KYWD resolves to "restrict" if
408 * an ISO C99 compiler is used, "__restrict" for c++ and "" (null string)
409 * if any other compiler is used. This allows for the use of single
410 * prototype declarations regardless of compiler version.
412 #if (defined(__STDC__) && defined(_STDC_C99))
413 #ifdef __cplusplus
414 #define _RESTRICT_KYWD __restrict
415 #else
417 * NOTE: The whitespace between the '#' and 'define' is significant.
418 * It foils gcc's fixincludes from defining a redundant 'restrict'.
420 /* CSTYLED */
421 # define _RESTRICT_KYWD restrict
422 #endif
423 #else
424 #define _RESTRICT_KYWD
425 #endif
428 * The following macro defines a value for the ISO C11 _Noreturn
429 * keyword so that _NORETURN_KYWD resolves to "_Noreturn" if
430 * an ISO C11 compiler is used and "" (null string) if any other
431 * compiler is used. This allows for the use of single prototype
432 * declarations regardless of compiler version.
434 #if (defined(__STDC__) && defined(_STDC_C11)) && !defined(__cplusplus)
435 #define _NORETURN_KYWD _Noreturn
436 #else
437 #define _NORETURN_KYWD
438 #endif
442 * The following macro indicates header support for the ANSI C++
443 * standard. The ISO/IEC designation for this is ISO/IEC FDIS 14882.
445 #define _ISO_CPP_14882_1998
448 * The following macro indicates header support for the C99 standard,
449 * ISO/IEC 9899:1999, Programming Languages - C.
451 #define _ISO_C_9899_1999
454 * The following macro indicates header support for the C99 standard,
455 * ISO/IEC 9899:2011, Programming Languages - C.
457 #define _ISO_C_9899_2011
460 * The following macro indicates header support for DTrace. The value is an
461 * integer that corresponds to the major version number for DTrace.
463 #define _DTRACE_VERSION 1
466 * The following macro indicates that we are on illumos, and serves to
467 * distinguish us from other SunOS derived systems.
469 #define _ILLUMOS 1
471 #ifdef __cplusplus
473 #endif
475 #endif /* _SYS_FEATURE_TESTS_H */