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