2 * Written by Joel Sherrill <joel@OARcorp.com>.
4 * COPYRIGHT (c) 1989-2014.
6 * On-Line Applications Research Corporation (OAR).
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose without fee is hereby granted, provided that this entire notice
10 * is included in all copies of any software which is or includes a copy
11 * or modification of this software.
13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
14 * WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
15 * OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
16 * SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
21 #ifndef _SYS_FEATURES_H
22 #define _SYS_FEATURES_H
28 #include <_newlib_version.h>
30 /* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
32 # if defined __GNUC__ && defined __GNUC_MINOR__
33 # define __GNUC_PREREQ(maj, min) \
34 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
36 # define __GNUC_PREREQ(maj, min) 0
38 #endif /* __GNUC_PREREQ */
39 /* Version with trailing underscores for BSD compatibility. */
40 #define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi)
44 * Feature test macros control which symbols are exposed by the system
45 * headers. Any of these must be defined before including any headers.
47 * __STRICT_ANSI__ (defined by gcc -ansi, -std=c90, -std=c99, or -std=c11)
50 * _POSIX_SOURCE (deprecated by _POSIX_C_SOURCE=1)
51 * _POSIX_C_SOURCE >= 1
54 * _POSIX_C_SOURCE >= 2
57 * _POSIX_C_SOURCE >= 199309L
58 * POSIX.1b-1993 Real-time extensions
60 * _POSIX_C_SOURCE >= 199506L
61 * POSIX.1c-1995 Threads extensions
63 * _POSIX_C_SOURCE >= 200112L
64 * POSIX.1-2001 and C99
66 * _POSIX_C_SOURCE >= 200809L
69 * _POSIX_C_SOURCE >= 202405L
73 * POSIX.1-1990 and XPG4
75 * _XOPEN_SOURCE_EXTENDED
76 * SUSv1 (POSIX.2-1992 plus XPG4v2)
78 * _XOPEN_SOURCE >= 500
79 * SUSv2 (POSIX.1c-1995 plus XSI)
81 * _XOPEN_SOURCE >= 600
82 * SUSv3 (POSIX.1-2001 plus XSI) and C99
84 * _XOPEN_SOURCE >= 700
85 * SUSv4 (POSIX.1-2008 plus XSI)
87 * _ISOC99_SOURCE or gcc -std=c99 or g++
90 * _ISOC11_SOURCE or gcc -std=c11 or g++ -std=c++11
93 * _ISOC23_SOURCE or _ISOC2X_SOURCE or gcc -std=c23 or g++ -std=c++20
96 * _ATFILE_SOURCE (implied by _POSIX_C_SOURCE >= 200809L)
99 * _LARGEFILE_SOURCE (deprecated by _XOPEN_SOURCE >= 500)
103 * All of the above plus GNU extensions
105 * _BSD_SOURCE (deprecated by _DEFAULT_SOURCE)
106 * _SVID_SOURCE (deprecated by _DEFAULT_SOURCE)
107 * _DEFAULT_SOURCE (or none of the above)
108 * POSIX-1.2008 with BSD and SVr4 extensions
110 * _FORTIFY_SOURCE = 1, 2 or 3
111 * Object Size Checking function wrappers
114 /* Remap the old name _ISOC2X_SOURCE to _ISOC23_SOURCE. */
115 #ifdef _ISOC2X_SOURCE
116 # undef _ISOC2X_SOURCE
117 # undef _ISOC23_SOURCE
118 # define _ISOC23_SOURCE 1
122 #undef _ATFILE_SOURCE
123 #define _ATFILE_SOURCE 1
124 #undef _DEFAULT_SOURCE
125 #define _DEFAULT_SOURCE 1
126 #undef _ISOC99_SOURCE
127 #define _ISOC99_SOURCE 1
128 #undef _ISOC11_SOURCE
129 #define _ISOC11_SOURCE 1
130 #undef _ISOC23_SOURCE
131 #define _ISOC23_SOURCE 1
133 #define _POSIX_SOURCE 1
134 #undef _POSIX_C_SOURCE
135 #define _POSIX_C_SOURCE 200809L
137 #define _XOPEN_SOURCE 700
138 #undef _XOPEN_SOURCE_EXTENDED
139 #define _XOPEN_SOURCE_EXTENDED 1
140 #endif /* _GNU_SOURCE */
142 #if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \
143 (!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE) && \
144 !defined(_ISOC99_SOURCE) && !defined(_POSIX_SOURCE) && \
145 !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE))
146 #undef _DEFAULT_SOURCE
147 #define _DEFAULT_SOURCE 1
150 #if defined(_DEFAULT_SOURCE)
152 #define _POSIX_SOURCE 1
153 #undef _POSIX_C_SOURCE
154 #define _POSIX_C_SOURCE 202405L
157 #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \
158 ((!defined(__STRICT_ANSI__) && !defined(_ANSI_SOURCE)) || \
159 (_XOPEN_SOURCE - 0) >= 500)
160 #define _POSIX_SOURCE 1
161 #if !defined(_XOPEN_SOURCE) || (_XOPEN_SOURCE - 0) >= 700
162 #define _POSIX_C_SOURCE 200809L
163 #elif (_XOPEN_SOURCE - 0) >= 600
164 #define _POSIX_C_SOURCE 200112L
165 #elif (_XOPEN_SOURCE - 0) >= 500
166 #define _POSIX_C_SOURCE 199506L
167 #elif (_XOPEN_SOURCE - 0) < 500
168 #define _POSIX_C_SOURCE 2
172 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809
173 #undef _ATFILE_SOURCE
174 #define _ATFILE_SOURCE 1
178 * The following private macros are used throughout the headers to control
179 * which symbols should be exposed. They are for internal use only, as
180 * indicated by the leading double underscore, and must never be used outside
184 * any version of POSIX.1; enabled by default, or with _POSIX_SOURCE,
185 * any value of _POSIX_C_SOURCE, or _XOPEN_SOURCE >= 500.
187 * __POSIX_VISIBLE >= 2
188 * POSIX.2-1992; enabled by default, with _POSIX_C_SOURCE >= 2,
189 * or _XOPEN_SOURCE >= 500.
191 * __POSIX_VISIBLE >= 199309
192 * POSIX.1b-1993; enabled by default, with _POSIX_C_SOURCE >= 199309L,
193 * or _XOPEN_SOURCE >= 500.
195 * __POSIX_VISIBLE >= 199506
196 * POSIX.1c-1995; enabled by default, with _POSIX_C_SOURCE >= 199506L,
197 * or _XOPEN_SOURCE >= 500.
199 * __POSIX_VISIBLE >= 200112
200 * POSIX.1-2001; enabled by default, with _POSIX_C_SOURCE >= 200112L,
201 * or _XOPEN_SOURCE >= 600.
203 * __POSIX_VISIBLE >= 200809
204 * POSIX.1-2008; enabled by default, with _POSIX_C_SOURCE >= 200809L,
205 * or _XOPEN_SOURCE >= 700.
207 * __POSIX_VISIBLE >= 202405
208 * POSIX.1-2024; enabled by default, with _POSIX_C_SOURCE >= 202405L,
209 * or _XOPEN_SOURCE >= 700.
212 * XPG4 XSI extensions; enabled with any version of _XOPEN_SOURCE.
215 * SUSv1 XSI extensions; enabled with both _XOPEN_SOURCE and
216 * _XOPEN_SOURCE_EXTENDED together.
218 * __XSI_VISIBLE >= 500
219 * SUSv2 XSI extensions; enabled with _XOPEN_SOURCE >= 500.
221 * __XSI_VISIBLE >= 600
222 * SUSv3 XSI extensions; enabled with _XOPEN_SOURCE >= 600.
224 * __XSI_VISIBLE >= 700
225 * SUSv4 XSI extensions; enabled with _XOPEN_SOURCE >= 700.
227 * __ISO_C_VISIBLE >= 1999
228 * ISO C99; enabled with gcc -std=c99 or newer (on by default since GCC 5),
229 * any version of C++, or with _ISOC99_SOURCE, _POSIX_C_SOURCE >= 200112L,
230 * or _XOPEN_SOURCE >= 600.
232 * __ISO_C_VISIBLE >= 2011
233 * ISO C11; enabled with gcc -std=c11 or newer (on by default since GCC 5),
234 * g++ -std=c++11 or newer (on by default since GCC 6), or with
237 * __ISO_C_VISIBLE >= 2020
238 * ISO C23; enabled with gcc -std=c23 or newer,
239 * g++ -std=c++20 or newer, or with
240 * _ISOC23_SOURCE or _ISOC2x_SOURCE.
243 * "at" functions; enabled by default, with _ATFILE_SOURCE,
244 * _POSIX_C_SOURCE >= 200809L, or _XOPEN_SOURCE >= 700.
246 * __LARGEFILE_VISIBLE
247 * fseeko, ftello; enabled with _LARGEFILE_SOURCE or _XOPEN_SOURCE >= 500.
250 * BSD extensions; enabled by default, or with _BSD_SOURCE.
253 * SVr4 extensions; enabled by default, or with _SVID_SOURCE.
256 * Extensions found in both BSD and SVr4 (shorthand for
257 * (__BSD_VISIBLE || __SVID_VISIBLE)), or newlib-specific
258 * extensions; enabled by default.
261 * GNU extensions; enabled with _GNU_SOURCE.
263 * __SSP_FORTIFY_LEVEL
264 * Object Size Checking; defined to 0 (off), 1, 2 or 3.
266 * In all cases above, "enabled by default" means either by defining
267 * _DEFAULT_SOURCE, or by not defining any of the public feature test macros.
270 #ifdef _ATFILE_SOURCE
271 #define __ATFILE_VISIBLE 1
273 #define __ATFILE_VISIBLE 0
276 #ifdef _DEFAULT_SOURCE
277 #define __BSD_VISIBLE 1
279 #define __BSD_VISIBLE 0
283 #define __GNU_VISIBLE 1
285 #define __GNU_VISIBLE 0
288 #if defined(_ISOC23_SOURCE) || \
289 (__STDC_VERSION__ - 0) > 201710L || (__cplusplus - 0) >= 202002L
290 #define __ISO_C_VISIBLE 2020
291 #elif defined(_ISOC11_SOURCE) || \
292 (__STDC_VERSION__ - 0) >= 201112L || (__cplusplus - 0) >= 201103L
293 #define __ISO_C_VISIBLE 2011
294 #elif defined(_ISOC99_SOURCE) || (_POSIX_C_SOURCE - 0) >= 200112L || \
295 (__STDC_VERSION__ - 0) >= 199901L || defined(__cplusplus)
296 #define __ISO_C_VISIBLE 1999
298 #define __ISO_C_VISIBLE 1990
301 #if defined(_LARGEFILE_SOURCE) || (_XOPEN_SOURCE - 0) >= 500
302 #define __LARGEFILE_VISIBLE 1
304 #define __LARGEFILE_VISIBLE 0
307 #ifdef _DEFAULT_SOURCE
308 #define __MISC_VISIBLE 1
310 #define __MISC_VISIBLE 0
313 #if (_POSIX_C_SOURCE - 0) >= 202405L
314 #define __POSIX_VISIBLE 202405
315 #elif (_POSIX_C_SOURCE - 0) >= 200809L
316 #define __POSIX_VISIBLE 200809
317 #elif (_POSIX_C_SOURCE - 0) >= 200112L
318 #define __POSIX_VISIBLE 200112
319 #elif (_POSIX_C_SOURCE - 0) >= 199506L
320 #define __POSIX_VISIBLE 199506
321 #elif (_POSIX_C_SOURCE - 0) >= 199309L
322 #define __POSIX_VISIBLE 199309
323 #elif (_POSIX_C_SOURCE - 0) >= 2 || defined(_XOPEN_SOURCE)
324 #define __POSIX_VISIBLE 199209
325 #elif defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
326 #define __POSIX_VISIBLE 199009
328 #define __POSIX_VISIBLE 0
331 #ifdef _DEFAULT_SOURCE
332 #define __SVID_VISIBLE 1
334 #define __SVID_VISIBLE 0
337 #if (_XOPEN_SOURCE - 0) >= 700
338 #define __XSI_VISIBLE 700
339 #elif (_XOPEN_SOURCE - 0) >= 600
340 #define __XSI_VISIBLE 600
341 #elif (_XOPEN_SOURCE - 0) >= 500
342 #define __XSI_VISIBLE 500
343 #elif defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)
344 #define __XSI_VISIBLE 4
345 #elif defined(_XOPEN_SOURCE)
346 #define __XSI_VISIBLE 1
348 #define __XSI_VISIBLE 0
351 #if _FORTIFY_SOURCE > 0 && !defined(__cplusplus) && !defined(__lint__) && \
352 (__OPTIMIZE__ > 0 || defined(__clang__)) && __GNUC_PREREQ__(4, 1) && \
354 # if _FORTIFY_SOURCE > 2 && defined(__has_builtin)
355 # if __has_builtin(__builtin_dynamic_object_size)
356 # define __SSP_FORTIFY_LEVEL 3
358 # define __SSP_FORTIFY_LEVEL 2
360 # elif _FORTIFY_SOURCE > 1
361 # define __SSP_FORTIFY_LEVEL 2
363 # define __SSP_FORTIFY_LEVEL 1
366 # define __SSP_FORTIFY_LEVEL 0
369 /* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */
372 #define _POSIX_JOB_CONTROL 1
373 #define _POSIX_SAVED_IDS 1
374 #define _POSIX_VERSION 199309L
375 #define _POSIX_ASYNCHRONOUS_IO 1
376 #define _POSIX_FSYNC 1
377 #define _POSIX_MAPPED_FILES 1
378 #define _POSIX_MEMLOCK 1
379 #define _POSIX_MEMLOCK_RANGE 1
380 #define _POSIX_MEMORY_PROTECTION 1
381 #define _POSIX_MESSAGE_PASSING 1
382 #define _POSIX_MONOTONIC_CLOCK 200112L
383 #define _POSIX_CLOCK_SELECTION 200112L
384 #define _POSIX_PRIORITIZED_IO 1
385 #define _POSIX_PRIORITY_SCHEDULING 1
386 #define _POSIX_REALTIME_SIGNALS 1
387 #define _POSIX_SEMAPHORES 1
388 #define _POSIX_SHARED_MEMORY_OBJECTS 1
389 #define _POSIX_SYNCHRONIZED_IO 1
390 #define _POSIX_TIMERS 1
391 #define _POSIX_BARRIERS 200112L
392 #define _POSIX_READER_WRITER_LOCKS 200112L
393 #define _POSIX_SPIN_LOCKS 200112L
396 /* In P1003.1b but defined by drafts at least as early as P1003.1c/D10 */
397 #define _POSIX_THREADS 1
398 #define _POSIX_THREAD_ATTR_STACKADDR 1
399 #define _POSIX_THREAD_ATTR_STACKSIZE 1
400 #define _POSIX_THREAD_PRIORITY_SCHEDULING 1
401 #define _POSIX_THREAD_PRIO_INHERIT 1
402 #define _POSIX_THREAD_PRIO_PROTECT 1
403 #define _POSIX_THREAD_PROCESS_SHARED 1
404 #define _POSIX_THREAD_SAFE_FUNCTIONS 1
406 /* P1003.4b/D8 defines the constants below this comment. */
407 #define _POSIX_SPAWN 1
408 #define _POSIX_TIMEOUTS 1
409 #define _POSIX_CPUTIME 1
410 #define _POSIX_THREAD_CPUTIME 1
411 #define _POSIX_SPORADIC_SERVER 1
412 #define _POSIX_THREAD_SPORADIC_SERVER 1
413 #define _POSIX_DEVICE_CONTROL 1
414 #define _POSIX_DEVCTL_DIRECTION 1
415 #define _POSIX_INTERRUPT_CONTROL 1
416 #define _POSIX_ADVISORY_INFO 1
418 /* UNIX98 added some new pthread mutex attributes */
419 #define _UNIX98_THREAD_MUTEX_ATTRIBUTES 1
421 /* POSIX 1003.26-2003 defined device control method */
422 #define _POSIX_26_VERSION 200312L
426 /* XMK loosely adheres to POSIX -- 1003.1 */
428 #define _POSIX_THREADS 1
429 #define _POSIX_THREAD_PRIORITY_SCHEDULING 1
434 # define _POSIX_JOB_CONTROL 1
435 # define _POSIX_SAVED_IDS 1
436 # define _POSIX_VERSION 199009L
441 #if __POSIX_VISIBLE >= 202405
442 #define _POSIX_VERSION 202405L
443 #define _POSIX2_VERSION 202405L
444 #elif __POSIX_VISIBLE >= 200809
445 #define _POSIX_VERSION 200809L
446 #define _POSIX2_VERSION 200809L
447 #elif __POSIX_VISIBLE >= 200112
448 #define _POSIX_VERSION 200112L
449 #define _POSIX2_VERSION 200112L
450 #elif __POSIX_VISIBLE >= 199506
451 #define _POSIX_VERSION 199506L
452 #define _POSIX2_VERSION 199506L
453 #elif __POSIX_VISIBLE >= 199309
454 #define _POSIX_VERSION 199309L
455 #define _POSIX2_VERSION 199209L
456 #elif __POSIX_VISIBLE >= 199209
457 #define _POSIX_VERSION 199009L
458 #define _POSIX2_VERSION 199209L
459 #elif __POSIX_VISIBLE
460 #define _POSIX_VERSION 199009L
462 #if __XSI_VISIBLE >= 4
463 #define _XOPEN_VERSION __XSI_VISIBLE
466 #define _POSIX_ADVISORY_INFO 200809L
467 #define _POSIX_ASYNCHRONOUS_IO 200809L
468 #define _POSIX_BARRIERS 200809L
469 #define _POSIX_CHOWN_RESTRICTED 1
470 #define _POSIX_CLOCK_SELECTION 200809L
471 #define _POSIX_CPUTIME 200809L
472 #define _POSIX_FSYNC 200809L
473 #define _POSIX_IPV6 200809L
474 #define _POSIX_JOB_CONTROL 1
475 #define _POSIX_MAPPED_FILES 200809L
476 /* #define _POSIX_MEMLOCK -1 */
477 #define _POSIX_MEMLOCK_RANGE 200809L
478 #define _POSIX_MEMORY_PROTECTION 200809L
479 #define _POSIX_MESSAGE_PASSING 200809L
480 #define _POSIX_MONOTONIC_CLOCK 200809L
481 #define _POSIX_NO_TRUNC 1
482 /* #define _POSIX_PRIORITIZED_IO -1 */
483 #define _POSIX_PRIORITY_SCHEDULING 200809L
484 #define _POSIX_RAW_SOCKETS 200809L
485 #define _POSIX_READER_WRITER_LOCKS 200809L
486 #define _POSIX_REALTIME_SIGNALS 200809L
487 #define _POSIX_REGEXP 1
488 #define _POSIX_SAVED_IDS 1
489 #define _POSIX_SEMAPHORES 200809L
490 #define _POSIX_SHARED_MEMORY_OBJECTS 200809L
491 #define _POSIX_SHELL 1
492 #define _POSIX_SPAWN 200809L
493 #define _POSIX_SPIN_LOCKS 200809L
494 /* #define _POSIX_SPORADIC_SERVER -1 */
495 #define _POSIX_SYNCHRONIZED_IO 200809L
496 #define _POSIX_THREAD_ATTR_STACKADDR 200809L
497 #define _POSIX_THREAD_ATTR_STACKSIZE 200809L
498 #define _POSIX_THREAD_CPUTIME 200809L
499 /* #define _POSIX_THREAD_PRIO_INHERIT -1 */
500 /* #define _POSIX_THREAD_PRIO_PROTECT -1 */
501 #define _POSIX_THREAD_PRIORITY_SCHEDULING 200809L
502 #define _POSIX_THREAD_PROCESS_SHARED 200809L
503 #define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
504 /* #define _POSIX_THREAD_SPORADIC_SERVER -1 */
505 #define _POSIX_THREADS 200809L
506 #define _POSIX_TIMEOUTS 200809L
507 #define _POSIX_TIMERS 200809L
508 /* #define _POSIX_TRACE -1 */
509 /* #define _POSIX_TRACE_EVENT_FILTER -1 */
510 /* #define _POSIX_TRACE_INHERIT -1 */
511 /* #define _POSIX_TRACE_LOG -1 */
512 /* #define _POSIX_TYPED_MEMORY_OBJECTS -1 */
513 #define _POSIX_VDISABLE '\0'
515 #if __POSIX_VISIBLE >= 2
516 #define _POSIX2_C_VERSION _POSIX2_VERSION
517 #define _POSIX2_C_BIND _POSIX2_VERSION
518 #define _POSIX2_C_DEV _POSIX2_VERSION
519 #define _POSIX2_CHAR_TERM _POSIX2_VERSION
520 /* #define _POSIX2_FORT_DEV -1 */
521 /* #define _POSIX2_FORT_RUN -1 */
522 /* #define _POSIX2_LOCALEDEF -1 */
523 /* #define _POSIX2_PBS -1 */
524 /* #define _POSIX2_PBS_ACCOUNTING -1 */
525 /* #define _POSIX2_PBS_CHECKPOINT -1 */
526 /* #define _POSIX2_PBS_LOCATE -1 */
527 /* #define _POSIX2_PBS_MESSAGE -1 */
528 /* #define _POSIX2_PBS_TRACK -1 */
529 #define _POSIX2_SW_DEV _POSIX2_VERSION
530 #define _POSIX2_UPE _POSIX2_VERSION
531 #endif /* __POSIX_VISIBLE >= 2 */
533 #define _POSIX_V6_ILP32_OFF32 -1
535 #define _POSIX_V6_ILP32_OFFBIG -1
536 #define _POSIX_V6_LP64_OFF64 1
537 #define _POSIX_V6_LPBIG_OFFBIG 1
539 #define _POSIX_V6_ILP32_OFFBIG 1
540 #define _POSIX_V6_LP64_OFF64 -1
541 #define _POSIX_V6_LPBIG_OFFBIG -1
543 #define _POSIX_V7_ILP32_OFF32 _POSIX_V6_ILP32_OFF32
544 #define _POSIX_V7_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG
545 #define _POSIX_V7_LP64_OFF64 _POSIX_V6_LP64_OFF64
546 #define _POSIX_V7_LPBIG_OFFBIG _POSIX_V6_LPBIG_OFFBIG
547 #define _XBS5_ILP32_OFF32 _POSIX_V6_ILP32_OFF32
548 #define _XBS5_ILP32_OFFBIG _POSIX_V6_ILP32_OFFBIG
549 #define _XBS5_LP64_OFF64 _POSIX_V6_LP64_OFF64
550 #define _XBS5_LPBIG_OFFBIG _POSIX_V6_LPBIG_OFFBIG
553 #define _XOPEN_CRYPT 1
554 #define _XOPEN_ENH_I18N 1
555 /* #define _XOPEN_LEGACY -1 */
556 /* #define _XOPEN_REALTIME -1 */
557 /* #define _XOPEN_REALTIME_THREADS -1 */
559 /* #define _XOPEN_STREAMS -1 */
560 /* #define _XOPEN_UNIX -1 */
561 #endif /* __XSI_VISIBLE */
564 * newlib's wide char conversion functions were updated on
566 * to UNICODE version:
567 * 11.0.0 released 2018-06-05
569 #define __STDC_ISO_10646__ 201806L
571 #endif /* __CYGWIN__ */
576 #endif /* _SYS_FEATURES_H */