1/* Copyright (C) 1991-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#ifndef _FEATURES_H
19#define _FEATURES_H 1
20
21/* These are defined by the user (or the compiler)
22 to specify the desired environment:
23
24 __STRICT_ANSI__ ISO Standard C.
25 _ISOC99_SOURCE Extensions to ISO C89 from ISO C99.
26 _ISOC11_SOURCE Extensions to ISO C99 from ISO C11.
27 _ISOC2X_SOURCE Extensions to ISO C99 from ISO C2X.
28 __STDC_WANT_LIB_EXT2__
29 Extensions to ISO C99 from TR 27431-2:2010.
30 __STDC_WANT_IEC_60559_BFP_EXT__
31 Extensions to ISO C11 from TS 18661-1:2014.
32 __STDC_WANT_IEC_60559_FUNCS_EXT__
33 Extensions to ISO C11 from TS 18661-4:2015.
34 __STDC_WANT_IEC_60559_TYPES_EXT__
35 Extensions to ISO C11 from TS 18661-3:2015.
36
37 _POSIX_SOURCE IEEE Std 1003.1.
38 _POSIX_C_SOURCE If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2;
39 if >=199309L, add IEEE Std 1003.1b-1993;
40 if >=199506L, add IEEE Std 1003.1c-1995;
41 if >=200112L, all of IEEE 1003.1-2004
42 if >=200809L, all of IEEE 1003.1-2008
43 _XOPEN_SOURCE Includes POSIX and XPG things. Set to 500 if
44 Single Unix conformance is wanted, to 600 for the
45 sixth revision, to 700 for the seventh revision.
46 _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions.
47 _LARGEFILE_SOURCE Some more functions for correct standard I/O.
48 _LARGEFILE64_SOURCE Additional functionality from LFS for large files.
49 _FILE_OFFSET_BITS=N Select default filesystem interface.
50 _ATFILE_SOURCE Additional *at interfaces.
51 _GNU_SOURCE All of the above, plus GNU extensions.
52 _DEFAULT_SOURCE The default set of features (taking precedence over
53 __STRICT_ANSI__).
54
55 _FORTIFY_SOURCE Add security hardening to many library functions.
56 Set to 1 or 2; 2 performs stricter checks than 1.
57
58 _REENTRANT, _THREAD_SAFE
59 Obsolete; equivalent to _POSIX_C_SOURCE=199506L.
60
61 The `-ansi' switch to the GNU C compiler, and standards conformance
62 options such as `-std=c99', define __STRICT_ANSI__. If none of
63 these are defined, or if _DEFAULT_SOURCE is defined, the default is
64 to have _POSIX_SOURCE set to one and _POSIX_C_SOURCE set to
65 200809L, as well as enabling miscellaneous functions from BSD and
66 SVID. If more than one of these are defined, they accumulate. For
67 example __STRICT_ANSI__, _POSIX_SOURCE and _POSIX_C_SOURCE together
68 give you ISO C, 1003.1, and 1003.2, but nothing else.
69
70 These are defined by this file and are used by the
71 header files to decide what to declare or define:
72
73 __GLIBC_USE (F) Define things from feature set F. This is defined
74 to 1 or 0; the subsequent macros are either defined
75 or undefined, and those tests should be moved to
76 __GLIBC_USE.
77 __USE_ISOC11 Define ISO C11 things.
78 __USE_ISOC99 Define ISO C99 things.
79 __USE_ISOC95 Define ISO C90 AMD1 (C95) things.
80 __USE_ISOCXX11 Define ISO C++11 things.
81 __USE_POSIX Define IEEE Std 1003.1 things.
82 __USE_POSIX2 Define IEEE Std 1003.2 things.
83 __USE_POSIX199309 Define IEEE Std 1003.1, and .1b things.
84 __USE_POSIX199506 Define IEEE Std 1003.1, .1b, .1c and .1i things.
85 __USE_XOPEN Define XPG things.
86 __USE_XOPEN_EXTENDED Define X/Open Unix things.
87 __USE_UNIX98 Define Single Unix V2 things.
88 __USE_XOPEN2K Define XPG6 things.
89 __USE_XOPEN2KXSI Define XPG6 XSI things.
90 __USE_XOPEN2K8 Define XPG7 things.
91 __USE_XOPEN2K8XSI Define XPG7 XSI things.
92 __USE_LARGEFILE Define correct standard I/O things.
93 __USE_LARGEFILE64 Define LFS things with separate names.
94 __USE_FILE_OFFSET64 Define 64bit interface as default.
95 __USE_MISC Define things from 4.3BSD or System V Unix.
96 __USE_ATFILE Define *at interfaces and AT_* constants for them.
97 __USE_GNU Define GNU extensions.
98 __USE_FORTIFY_LEVEL Additional security measures used, according to level.
99
100 The macros `__GNU_LIBRARY__', `__GLIBC__', and `__GLIBC_MINOR__' are
101 defined by this file unconditionally. `__GNU_LIBRARY__' is provided
102 only for compatibility. All new code should use the other symbols
103 to test for features.
104
105 All macros listed above as possibly being defined by this file are
106 explicitly undefined if they are not explicitly defined.
107 Feature-test macros that are not defined by the user or compiler
108 but are implied by the other feature-test macros defined (or by the
109 lack of any definitions) are defined by the file.
110
111 ISO C feature test macros depend on the definition of the macro
112 when an affected header is included, not when the first system
113 header is included, and so they are handled in
114 <bits/libc-header-start.h>, which does not have a multiple include
115 guard. Feature test macros that can be handled from the first
116 system header included are handled here. */
117
118
119/* Undefine everything, so we get a clean slate. */
120#undef __USE_ISOC11
121#undef __USE_ISOC99
122#undef __USE_ISOC95
123#undef __USE_ISOCXX11
124#undef __USE_POSIX
125#undef __USE_POSIX2
126#undef __USE_POSIX199309
127#undef __USE_POSIX199506
128#undef __USE_XOPEN
129#undef __USE_XOPEN_EXTENDED
130#undef __USE_UNIX98
131#undef __USE_XOPEN2K
132#undef __USE_XOPEN2KXSI
133#undef __USE_XOPEN2K8
134#undef __USE_XOPEN2K8XSI
135#undef __USE_LARGEFILE
136#undef __USE_LARGEFILE64
137#undef __USE_FILE_OFFSET64
138#undef __USE_MISC
139#undef __USE_ATFILE
140#undef __USE_GNU
141#undef __USE_FORTIFY_LEVEL
142#undef __KERNEL_STRICT_NAMES
143#undef __GLIBC_USE_ISOC2X
144#undef __GLIBC_USE_DEPRECATED_GETS
145#undef __GLIBC_USE_DEPRECATED_SCANF
146
147/* Suppress kernel-name space pollution unless user expressedly asks
148 for it. */
149#ifndef _LOOSE_KERNEL_NAMES
150# define __KERNEL_STRICT_NAMES
151#endif
152
153/* Convenience macro to test the version of gcc.
154 Use like this:
155 #if __GNUC_PREREQ (2,8)
156 ... code requiring gcc 2.8 or later ...
157 #endif
158 Note: only works for GCC 2.0 and later, because __GNUC_MINOR__ was
159 added in 2.0. */
160#if defined __GNUC__ && defined __GNUC_MINOR__
161# define __GNUC_PREREQ(maj, min) \
162 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
163#else
164# define __GNUC_PREREQ(maj, min) 0
165#endif
166
167/* Similarly for clang. Features added to GCC after version 4.2 may
168 or may not also be available in clang, and clang's definitions of
169 __GNUC(_MINOR)__ are fixed at 4 and 2 respectively. Not all such
170 features can be queried via __has_extension/__has_feature. */
171#if defined __clang_major__ && defined __clang_minor__
172# define __glibc_clang_prereq(maj, min) \
173 ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
174#else
175# define __glibc_clang_prereq(maj, min) 0
176#endif
177
178/* Whether to use feature set F. */
179#define __GLIBC_USE(F) __GLIBC_USE_ ## F
180
181/* _BSD_SOURCE and _SVID_SOURCE are deprecated aliases for
182 _DEFAULT_SOURCE. If _DEFAULT_SOURCE is present we do not
183 issue a warning; the expectation is that the source is being
184 transitioned to use the new macro. */
185#if (defined _BSD_SOURCE || defined _SVID_SOURCE) \
186 && !defined _DEFAULT_SOURCE
187# warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
188# undef _DEFAULT_SOURCE
189# define _DEFAULT_SOURCE 1
190#endif
191
192/* If _GNU_SOURCE was defined by the user, turn on all the other features. */
193#ifdef _GNU_SOURCE
194# undef _ISOC95_SOURCE
195# define _ISOC95_SOURCE 1
196# undef _ISOC99_SOURCE
197# define _ISOC99_SOURCE 1
198# undef _ISOC11_SOURCE
199# define _ISOC11_SOURCE 1
200# undef _ISOC2X_SOURCE
201# define _ISOC2X_SOURCE 1
202# undef _POSIX_SOURCE
203# define _POSIX_SOURCE 1
204# undef _POSIX_C_SOURCE
205# define _POSIX_C_SOURCE 200809L
206# undef _XOPEN_SOURCE
207# define _XOPEN_SOURCE 700
208# undef _XOPEN_SOURCE_EXTENDED
209# define _XOPEN_SOURCE_EXTENDED 1
210# undef _LARGEFILE64_SOURCE
211# define _LARGEFILE64_SOURCE 1
212# undef _DEFAULT_SOURCE
213# define _DEFAULT_SOURCE 1
214# undef _ATFILE_SOURCE
215# define _ATFILE_SOURCE 1
216#endif
217
218/* If nothing (other than _GNU_SOURCE and _DEFAULT_SOURCE) is defined,
219 define _DEFAULT_SOURCE. */
220#if (defined _DEFAULT_SOURCE \
221 || (!defined __STRICT_ANSI__ \
222 && !defined _ISOC99_SOURCE && !defined _ISOC11_SOURCE \
223 && !defined _ISOC2X_SOURCE \
224 && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE \
225 && !defined _XOPEN_SOURCE))
226# undef _DEFAULT_SOURCE
227# define _DEFAULT_SOURCE 1
228#endif
229
230/* This is to enable the ISO C2X extension. */
231#if (defined _ISOC2X_SOURCE \
232 || (defined __STDC_VERSION__ && __STDC_VERSION__ > 201710L))
233# define __GLIBC_USE_ISOC2X 1
234#else
235# define __GLIBC_USE_ISOC2X 0
236#endif
237
238/* This is to enable the ISO C11 extension. */
239#if (defined _ISOC11_SOURCE || defined _ISOC2X_SOURCE \
240 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L))
241# define __USE_ISOC11 1
242#endif
243
244/* This is to enable the ISO C99 extension. */
245#if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
246 || defined _ISOC2X_SOURCE \
247 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
248# define __USE_ISOC99 1
249#endif
250
251/* This is to enable the ISO C90 Amendment 1:1995 extension. */
252#if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
253 || defined _ISOC2X_SOURCE \
254 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199409L))
255# define __USE_ISOC95 1
256#endif
257
258#ifdef __cplusplus
259/* This is to enable compatibility for ISO C++17. */
260# if __cplusplus >= 201703L
261# define __USE_ISOC11 1
262# endif
263/* This is to enable compatibility for ISO C++11.
264 Check the temporary macro for now, too. */
265# if __cplusplus >= 201103L || defined __GXX_EXPERIMENTAL_CXX0X__
266# define __USE_ISOCXX11 1
267# define __USE_ISOC99 1
268# endif
269#endif
270
271/* If none of the ANSI/POSIX macros are defined, or if _DEFAULT_SOURCE
272 is defined, use POSIX.1-2008 (or another version depending on
273 _XOPEN_SOURCE). */
274#ifdef _DEFAULT_SOURCE
275# if !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE
276# define __USE_POSIX_IMPLICITLY 1
277# endif
278# undef _POSIX_SOURCE
279# define _POSIX_SOURCE 1
280# undef _POSIX_C_SOURCE
281# define _POSIX_C_SOURCE 200809L
282#endif
283
284#if ((!defined __STRICT_ANSI__ \
285 || (defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 500)) \
286 && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
287# define _POSIX_SOURCE 1
288# if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
289# define _POSIX_C_SOURCE 2
290# elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600
291# define _POSIX_C_SOURCE 199506L
292# elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 700
293# define _POSIX_C_SOURCE 200112L
294# else
295# define _POSIX_C_SOURCE 200809L
296# endif
297# define __USE_POSIX_IMPLICITLY 1
298#endif
299
300/* Some C libraries once required _REENTRANT and/or _THREAD_SAFE to be
301 defined in all multithreaded code. GNU libc has not required this
302 for many years. We now treat them as compatibility synonyms for
303 _POSIX_C_SOURCE=199506L, which is the earliest level of POSIX with
304 comprehensive support for multithreaded code. Using them never
305 lowers the selected level of POSIX conformance, only raises it. */
306#if ((!defined _POSIX_C_SOURCE || (_POSIX_C_SOURCE - 0) < 199506L) \
307 && (defined _REENTRANT || defined _THREAD_SAFE))
308# define _POSIX_SOURCE 1
309# undef _POSIX_C_SOURCE
310# define _POSIX_C_SOURCE 199506L
311#endif
312
313#if (defined _POSIX_SOURCE \
314 || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1) \
315 || defined _XOPEN_SOURCE)
316# define __USE_POSIX 1
317#endif
318
319#if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || defined _XOPEN_SOURCE
320# define __USE_POSIX2 1
321#endif
322
323#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L
324# define __USE_POSIX199309 1
325#endif
326
327#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199506L
328# define __USE_POSIX199506 1
329#endif
330
331#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200112L
332# define __USE_XOPEN2K 1
333# undef __USE_ISOC95
334# define __USE_ISOC95 1
335# undef __USE_ISOC99
336# define __USE_ISOC99 1
337#endif
338
339#if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200809L
340# define __USE_XOPEN2K8 1
341# undef _ATFILE_SOURCE
342# define _ATFILE_SOURCE 1
343#endif
344
345#ifdef _XOPEN_SOURCE
346# define __USE_XOPEN 1
347# if (_XOPEN_SOURCE - 0) >= 500
348# define __USE_XOPEN_EXTENDED 1
349# define __USE_UNIX98 1
350# undef _LARGEFILE_SOURCE
351# define _LARGEFILE_SOURCE 1
352# if (_XOPEN_SOURCE - 0) >= 600
353# if (_XOPEN_SOURCE - 0) >= 700
354# define __USE_XOPEN2K8 1
355# define __USE_XOPEN2K8XSI 1
356# endif
357# define __USE_XOPEN2K 1
358# define __USE_XOPEN2KXSI 1
359# undef __USE_ISOC95
360# define __USE_ISOC95 1
361# undef __USE_ISOC99
362# define __USE_ISOC99 1
363# endif
364# else
365# ifdef _XOPEN_SOURCE_EXTENDED
366# define __USE_XOPEN_EXTENDED 1
367# endif
368# endif
369#endif
370
371#ifdef _LARGEFILE_SOURCE
372# define __USE_LARGEFILE 1
373#endif
374
375#ifdef _LARGEFILE64_SOURCE
376# define __USE_LARGEFILE64 1
377#endif
378
379#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
380# define __USE_FILE_OFFSET64 1
381#endif
382
383#if defined _DEFAULT_SOURCE
384# define __USE_MISC 1
385#endif
386
387#ifdef _ATFILE_SOURCE
388# define __USE_ATFILE 1
389#endif
390
391#ifdef _GNU_SOURCE
392# define __USE_GNU 1
393#endif
394
395#if defined _FORTIFY_SOURCE && _FORTIFY_SOURCE > 0
396# if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
397# warning _FORTIFY_SOURCE requires compiling with optimization (-O)
398# elif !__GNUC_PREREQ (4, 1)
399# warning _FORTIFY_SOURCE requires GCC 4.1 or later
400# elif _FORTIFY_SOURCE > 1
401# define __USE_FORTIFY_LEVEL 2
402# else
403# define __USE_FORTIFY_LEVEL 1
404# endif
405#endif
406#ifndef __USE_FORTIFY_LEVEL
407# define __USE_FORTIFY_LEVEL 0
408#endif
409
410/* The function 'gets' existed in C89, but is impossible to use
411 safely. It has been removed from ISO C11 and ISO C++14. Note: for
412 compatibility with various implementations of <cstdio>, this test
413 must consider only the value of __cplusplus when compiling C++. */
414#if defined __cplusplus ? __cplusplus >= 201402L : defined __USE_ISOC11
415# define __GLIBC_USE_DEPRECATED_GETS 0
416#else
417# define __GLIBC_USE_DEPRECATED_GETS 1
418#endif
419
420/* GNU formerly extended the scanf functions with modified format
421 specifiers %as, %aS, and %a[...] that allocate a buffer for the
422 input using malloc. This extension conflicts with ISO C99, which
423 defines %a as a standalone format specifier that reads a floating-
424 point number; moreover, POSIX.1-2008 provides the same feature
425 using the modifier letter 'm' instead (%ms, %mS, %m[...]).
426
427 We now follow C99 unless GNU extensions are active and the compiler
428 is specifically in C89 or C++98 mode (strict or not). For
429 instance, with GCC, -std=gnu11 will have C99-compliant scanf with
430 or without -D_GNU_SOURCE, but -std=c89 -D_GNU_SOURCE will have the
431 old extension. */
432#if (defined __USE_GNU \
433 && (defined __cplusplus \
434 ? (__cplusplus < 201103L && !defined __GXX_EXPERIMENTAL_CXX0X__) \
435 : (!defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L)))
436# define __GLIBC_USE_DEPRECATED_SCANF 1
437#else
438# define __GLIBC_USE_DEPRECATED_SCANF 0
439#endif
440
441/* Get definitions of __STDC_* predefined macros, if the compiler has
442 not preincluded this header automatically. */
443#include <stdc-predef.h>
444
445/* This macro indicates that the installed library is the GNU C Library.
446 For historic reasons the value now is 6 and this will stay from now
447 on. The use of this variable is deprecated. Use __GLIBC__ and
448 __GLIBC_MINOR__ now (see below) when you want to test for a specific
449 GNU C library version and use the values in <gnu/lib-names.h> to get
450 the sonames of the shared libraries. */
451#undef __GNU_LIBRARY__
452#define __GNU_LIBRARY__ 6
453
454/* Major and minor version number of the GNU C library package. Use
455 these macros to test for features in specific releases. */
456#define __GLIBC__ 2
457#define __GLIBC_MINOR__ 31
458
459#define __GLIBC_PREREQ(maj, min) \
460 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
461
462/* This is here only because every header file already includes this one. */
463#ifndef __ASSEMBLER__
464# ifndef _SYS_CDEFS_H
465# include <sys/cdefs.h>
466# endif
467
468/* If we don't have __REDIRECT, prototypes will be missing if
469 __USE_FILE_OFFSET64 but not __USE_LARGEFILE[64]. */
470# if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
471# define __USE_LARGEFILE 1
472# define __USE_LARGEFILE64 1
473# endif
474
475#endif /* !ASSEMBLER */
476
477/* Decide whether we can define 'extern inline' functions in headers. */
478#if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
479 && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
480 && defined __extern_inline
481# define __USE_EXTERN_INLINES 1
482#endif
483
484
485/* This is here only because every header file already includes this one.
486 Get the definitions of all the appropriate `__stub_FUNCTION' symbols.
487 <gnu/stubs.h> contains `#define __stub_FUNCTION' when FUNCTION is a stub
488 that will always return failure (and set errno to ENOSYS). */
489#include <gnu/stubs.h>
490
491
492#endif /* features.h */
493