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