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