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