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