wait.2: Add ESRCH for when pid == INT_MIN
[man-pages.git] / man7 / feature_test_macros.7
blob77362ed2380f0e7a74d22afb1c524f7a6408ac77
1 .\" This manpage is Copyright (C) 2006, Michael Kerrisk
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH FEATURE_TEST_MACROS 7 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 feature_test_macros \- feature test macros
28 .SH DESCRIPTION
29 Feature test macros allow the programmer to control the definitions that
30 are exposed by system header files when a program is compiled.
31 .PP
32 .B NOTE:
33 In order to be effective, a feature test macro
34 .IR "must be defined before including any header files" .
35 This can be done either in the compilation command
36 .RI ( "cc \-DMACRO=value" )
37 or by defining the macro within the source code before
38 including any headers.
39 The requirement that the macro must be defined before including any
40 header file exists because header files may freely include one another.
41 Thus, for example, in the following lines, defining the
42 .B _GNU_SOURCE
43 macro may have no effect because the header
44 .I <abc.h>
45 itself includes
46 .I <xyz.h>
47 (POSIX explicitly allows this):
48 .PP
49 .in +4n
50 .EX
51 #include <abc.h>
52 #define _GNU_SOURCE
53 #include <xyz.h>
54 .EE
55 .in
56 .PP
57 Some feature test macros are useful for creating portable applications,
58 by preventing nonstandard definitions from being exposed.
59 Other macros can be used to expose nonstandard definitions that
60 are not exposed by default.
61 .PP
62 The precise effects of each of the feature test macros described below
63 can be ascertained by inspecting the
64 .I <features.h>
65 header file.
66 .BR Note :
67 applications do
68 .I not
69 need to directly include
70 .IR <features.h> ;
71 indeed, doing so is actively discouraged.
72 See NOTES.
73 .SS Specification of feature test macro requirements in manual pages
74 When a function requires that a feature test macro is defined,
75 the manual page SYNOPSIS typically includes a note of the following form
76 (this example from the
77 .BR acct (2)
78 manual page):
79 .PP
80 .RS
81 .B #include <unistd.h>
82 .PP
83 .BI "int acct(const char *" filename );
84 .PP
85 .RS -4
86 .EX
87 Feature Test Macro Requirements for glibc (see
88 .BR feature_test_macros (7)):
89 .EE
90 .RE
91 .PP
92 .BR acct ():
93 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
94 .RE
95 .PP
96 The
97 .B ||
98 means that in order to obtain the declaration of
99 .BR acct (2)
100 from
101 .IR <unistd.h> ,
102 .I either
103 of the following macro
104 definitions must be made before including any header files:
106 .in +4n
108 #define _BSD_SOURCE
109 #define _XOPEN_SOURCE        /* or any value < 500 */
113 Alternatively, equivalent definitions can be included in the
114 compilation command:
116 .in +4n
118 cc \-D_BSD_SOURCE
119 cc \-D_XOPEN_SOURCE           # Or any value < 500
123 Note that, as described below,
124 .BR "some feature test macros are defined by default" ,
125 so that it may not always be necessary to
126 explicitly specify the feature test macro(s) shown in the
127 SYNOPSIS.
129 In a few cases, manual pages use a shorthand for expressing the
130 feature test macro requirements (this example from
131 .BR readahead (2)):
133 .RS +4
135 .B #define _GNU_SOURCE
136 .B #include <fcntl.h>
138 .BI "ssize_t readahead(int " fd ", off64_t *" offset ", size_t " count );
142 This format is employed in cases where only a single
143 feature test macro can be used to expose the function
144 declaration, and that macro is not defined by default.
145 .SS Feature test macros understood by glibc
146 The paragraphs below explain how feature test macros are handled
147 in glibc 2.\fIx\fP,
148 .I x
149 > 0.
151 First, though, a summary of a few details for the impatient:
152 .IP * 3
153 The macros that you most likely need to use in modern source code are
154 .BR _POSIX_C_SOURCE
155 (for definitions from various versions of POSIX.1),
156 .BR _XOPEN_SOURCE
157 (for definitions from various versions of SUS),
158 .BR _GNU_SOURCE
159 (for GNU and/or Linux specific stuff), and
160 .BR _DEFAULT_SOURCE
161 (to get definitions that would normally be provided by default).
162 .IP *
163 Certain macros are defined with default values.
164 Thus, although one or more macros may be indicated as being
165 required in the SYNOPSIS of a man page,
166 it may not be necessary to define them explicitly.
167 Full details of the defaults are given later in this man page.
168 .IP *
169 Defining
170 .BR _XOPEN_SOURCE
171 with a value of 600 or greater produces the same effects as defining
172 .BR _POSIX_C_SOURCE
173 with a value of 200112L or greater.
174 Where one sees
176 .in +4n
178 _POSIX_C_SOURCE >= 200112L
182 in the feature test macro requirements in the SYNOPSIS of a man page,
183 it is implicit that the following has the same effect:
185 .in +4n
187 _XOPEN_SOURCE >= 600
190 .IP *
191 Defining
192 .BR _XOPEN_SOURCE
193 with a value of 700 or greater produces the same effects as defining
194 .BR _POSIX_C_SOURCE
195 with a value of 200809L or greater.
196 Where one sees
198 .in +4n
200 _POSIX_C_SOURCE >= 200809L
204 in the feature test macro requirements in the SYNOPSIS of a man page,
205 it is implicit that the following has the same effect:
207 .in +4n
209 _XOPEN_SOURCE >= 700
212 .\" The details in glibc 2.0 are simpler, but combining a
213 .\" a description of them with the details in later glibc versions
214 .\" would make for a complicated description.
216 Glibc understands the following feature test macros:
218 .B __STRICT_ANSI__
219 ISO Standard C.
220 This macro is implicitly defined by
221 .BR gcc (1)
222 when invoked with, for example, the
223 .I \-std=c99
225 .I \-ansi
226 flag.
228 .B _POSIX_C_SOURCE
229 Defining this macro causes header files to expose definitions as follows:
231 .IP \(bu 3
232 The value 1 exposes definitions conforming to POSIX.1-1990 and
233 ISO C (1990).
234 .IP \(bu
235 The value 2 or greater additionally exposes
236 definitions for POSIX.2-1992.
237 .IP \(bu
238 The value 199309L or greater additionally exposes
239 definitions for POSIX.1b (real-time extensions).
240 .\" 199506L functionality is available only since glibc 2.1
241 .IP \(bu
242 The value 199506L or greater additionally exposes
243 definitions for POSIX.1c (threads).
244 .IP \(bu
245 (Since glibc 2.3.3)
246 The value 200112L or greater additionally exposes definitions corresponding
247 to the POSIX.1-2001 base specification (excluding the XSI extension).
248 This value also causes C95 (since glibc 2.12) and
249 C99 (since glibc 2.10) features to be exposed
250 (in other words, the equivalent of defining
251 .BR _ISOC99_SOURCE ).
252 .IP \(bu
253 (Since glibc 2.10)
254 The value 200809L or greater additionally exposes definitions corresponding
255 to the POSIX.1-2008 base specification (excluding the XSI extension).
258 .B _POSIX_SOURCE
259 Defining this obsolete macro with any value is equivalent to defining
260 .B _POSIX_C_SOURCE
261 with the value 1.
263 Since this macro is obsolete,
264 its usage is generally not documented when discussing
265 feature test macro requirements in the man pages.
267 .B _XOPEN_SOURCE
268 Defining this macro causes header files to expose definitions as follows:
270 .IP \(bu 3
271 Defining with any value exposes
272 definitions conforming to POSIX.1, POSIX.2, and XPG4.
273 .IP \(bu
274 The value 500 or greater additionally exposes
275 definitions for SUSv2 (UNIX 98).
276 .IP \(bu
277 (Since glibc 2.2) The value 600 or greater additionally exposes
278 definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
279 plus the XSI extension) and C99 definitions.
280 .IP \(bu
281 (Since glibc 2.10) The value 700 or greater additionally exposes
282 definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
283 plus the XSI extension).
287 .B __STRICT_ANSI__
288 is not defined, or
289 .BR _XOPEN_SOURCE
290 is defined with a value greater than or equal to 500
291 .I and
292 neither
293 .B _POSIX_SOURCE
295 .B _POSIX_C_SOURCE
296 is explicitly defined, then
297 the following macros are implicitly defined:
299 .IP \(bu 3
300 .B _POSIX_SOURCE
301 is defined with the value 1.
302 .IP \(bu
303 .B _POSIX_C_SOURCE
304 is defined, according to the value of
305 .BR _XOPEN_SOURCE :
308 .BR _XOPEN_SOURCE " < 500"
309 .B _POSIX_C_SOURCE
310 is defined with the value 2.
312 .RB "500 <= " _XOPEN_SOURCE " < 600"
313 .B _POSIX_C_SOURCE
314 is defined with the value 199506L.
316 .RB "600 <= " _XOPEN_SOURCE " < 700"
317 .B _POSIX_C_SOURCE
318 is defined with the value 200112L.
320 .RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
321 .B _POSIX_C_SOURCE
322 is defined with the value 200809L.
326 In addition, defining
327 .BR _XOPEN_SOURCE
328 with a value of 500 or greater produces the same effects as defining
329 .BR _XOPEN_SOURCE_EXTENDED .
331 .B _XOPEN_SOURCE_EXTENDED
332 If this macro is defined,
333 .I and
334 .B _XOPEN_SOURCE
335 is defined, then expose definitions corresponding to the XPG4v2
336 (SUSv1) UNIX extensions (UNIX 95).
337 Defining
338 .B _XOPEN_SOURCE
339 with a value of 500 or more also produces the same effect as defining
340 .BR _XOPEN_SOURCE_EXTENDED .
341 Use of
342 .BR _XOPEN_SOURCE_EXTENDED
343 in new source code should be avoided.
345 Since defining
346 .B _XOPEN_SOURCE
347 with a value of 500 or more has the same effect as defining
348 .BR _XOPEN_SOURCE_EXTENDED ,
349 the latter (obsolete) feature test macro is generally not described in the
350 SYNOPSIS in man pages.
352 .BR _ISOC99_SOURCE " (since glibc 2.1.3)"
353 Exposes declarations consistent with the ISO C99 standard.
355 Earlier glibc 2.1.x versions recognized an equivalent macro named
356 .B _ISOC9X_SOURCE
357 (because the C99 standard had not then been finalized).
358 Although the use of this macro is obsolete, glibc continues
359 to recognize it for backward compatibility.
361 Defining
362 .B _ISOC99_SOURCE
363 also exposes ISO C (1990) Amendment 1 ("C95") definitions.
364 (The primary change in C95 was support for international character sets.)
366 Invoking the C compiler with the option
367 .IR \-std=c99
368 produces the same effects as defining this macro.
370 .BR _ISOC11_SOURCE " (since glibc 2.16)"
371 Exposes declarations consistent with the ISO C11 standard.
372 Defining this macro also enables C99 and C95 features (like
373 .BR _ISOC99_SOURCE ).
375 Invoking the C compiler with the option
376 .IR \-std=c11
377 produces the same effects as defining this macro.
379 .B _LARGEFILE64_SOURCE
380 Expose definitions for the alternative API specified by the
381 LFS (Large File Summit) as a "transitional extension" to the
382 Single UNIX Specification.
383 (See
384 .UR http:\:/\:/opengroup.org\:/platform\:/lfs.html
385 .UE .)
386 The alternative API consists of a set of new objects
387 (i.e., functions and types) whose names are suffixed with "64"
388 (e.g.,
389 .I off64_t
390 versus
391 .IR off_t ,
392 .BR lseek64 ()
393 versus
394 .BR lseek (),
395 etc.).
396 New programs should not employ this macro; instead
397 .I _FILE_OFFSET_BITS=64
398 should be employed.
400 .BR _LARGEFILE_SOURCE
401 This macro was historically used to expose certain functions (specifically
402 .BR fseeko (3)
404 .BR ftello (3))
405 that address limitations of earlier APIs
406 .RB ( fseek (3)
408 .BR ftell (3))
409 that use
410 .IR "long"
411 for file offsets.
412 This macro is implicitly defined if
413 .BR _XOPEN_SOURCE
414 is defined with a value greater than or equal to 500.
415 New programs should not employ this macro;
416 defining
417 .BR _XOPEN_SOURCE
418 as just described or defining
419 .B _FILE_OFFSET_BITS
420 with the value 64 is the preferred mechanism to achieve the same result.
422 .B _FILE_OFFSET_BITS
423 Defining this macro with the value 64
424 automatically converts references to 32-bit functions and data types
425 related to file I/O and filesystem operations into references to
426 their 64-bit counterparts.
427 This is useful for performing I/O on large files (> 2 Gigabytes)
428 on 32-bit systems.
429 (Defining this macro permits correctly written programs to use
430 large files with only a recompilation being required.)
432 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
433 and on those systems this macro has no effect.
435 .BR _BSD_SOURCE " (deprecated since glibc 2.20)"
436 Defining this macro with any value causes header files to expose
437 BSD-derived definitions.
439 In glibc versions up to and including 2.18,
440 defining this macro also causes BSD definitions to be preferred in
441 some situations where standards conflict, unless one or more of
442 .BR _SVID_SOURCE ,
443 .BR _POSIX_SOURCE ,
444 .BR _POSIX_C_SOURCE ,
445 .BR _XOPEN_SOURCE ,
446 .BR _XOPEN_SOURCE_EXTENDED ,
448 .B _GNU_SOURCE
449 is defined, in which case BSD definitions are disfavored.
450 Since glibc 2.19,
451 .B _BSD_SOURCE
452 no longer causes BSD definitions to be preferred in case of conflicts.
454 Since glibc 2.20, this macro is deprecated.
455 .\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
456 .\" commit 498afc54dfee41d33ba519f496e96480badace8e
457 .\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
458 It now has the same effect as defining
459 .BR _DEFAULT_SOURCE ,
460 but generates a compile-time warning (unless
461 .BR _DEFAULT_SOURCE
462 .\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
463 is also defined).
465 .B _DEFAULT_SOURCE
466 instead.
467 To allow code that requires
468 .BR _BSD_SOURCE
469 in glibc 2.19 and earlier and
470 .BR _DEFAULT_SOURCE
471 in glibc 2.20 and later to compile without warnings, define
472 .I both
473 .B _BSD_SOURCE
475 .BR _DEFAULT_SOURCE .
477 .BR _SVID_SOURCE " (deprecated since glibc 2.20)"
478 Defining this macro with any value causes header files to expose
479 System V-derived definitions.
480 (SVID == System V Interface Definition; see
481 .BR standards (7).)
483 Since glibc 2.20, this macro is deprecated in the same fashion as
484 .BR _BSD_SOURCE .
486 .BR _DEFAULT_SOURCE " (since glibc 2.19)"
487 This macro can be defined to ensure that the "default"
488 definitions are provided even when the defaults would otherwise
489 be disabled,
490 as happens when individual macros are explicitly defined,
491 or the compiler is invoked in one of its "standard" modes (e.g.,
492 .IR "cc\ \-std=c99" ).
493 Defining
494 .B _DEFAULT_SOURCE
495 without defining other individual macros
496 or invoking the compiler in one of its "standard" modes has no effect.
498 The "default" definitions comprise those required by POSIX.1-2008 and ISO C99,
499 as well as various definitions originally derived from BSD and System V.
500 On glibc 2.19 and earlier, these defaults were approximately equivalent
501 to explicitly defining the following:
503     cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
505 .BR _ATFILE_SOURCE " (since glibc 2.4)"
506 Defining this macro with any value causes header files to expose
507 declarations of a range of functions with the suffix "at";
509 .BR openat (2).
510 Since glibc 2.10, this macro is also implicitly defined if
511 .BR _POSIX_C_SOURCE
512 is defined with a value greater than or equal to 200809L.
514 .B _GNU_SOURCE
515 Defining this macro (with any value) implicitly defines
516 .BR _ATFILE_SOURCE ,
517 .BR _LARGEFILE64_SOURCE ,
518 .BR _ISOC99_SOURCE ,
519 .BR _XOPEN_SOURCE_EXTENDED ,
520 .BR _POSIX_SOURCE ,
521 .B _POSIX_C_SOURCE
522 with the value 200809L
523 (200112L in glibc versions before 2.10;
524 199506L in glibc versions before 2.5;
525 199309L in glibc versions before 2.1)
527 .B _XOPEN_SOURCE
528 with the value 700
529 (600 in glibc versions before 2.10;
530 500 in glibc versions before 2.2).
531 In addition, various GNU-specific extensions are also exposed.
533 Since glibc 2.19, defining
534 .BR _GNU_SOURCE
535 also has the effect of implicitly defining
536 .BR _DEFAULT_SOURCE .
537 In glibc versions before 2.20, defining
538 .BR _GNU_SOURCE
539 also had the effect of implicitly defining
540 .BR _BSD_SOURCE
542 .BR _SVID_SOURCE .
544 .B _REENTRANT
545 Historically, on various C libraries
546 it was necessary to define this macro in all
547 multithreaded code.
548 .\" Zack Weinberg
549 .\"     There did once exist C libraries where it was necessary. The ones
550 .\"     I remember were proprietary Unix vendor libcs from the mid-1990s
551 .\"     You would get completely unlocked stdio without _REENTRANT.
552 (Some C libraries may still require this.)
553 In glibc,
554 this macro also exposed definitions of certain reentrant functions.
556 However, glibc has been thread-safe by default for many years;
557 since glibc 2.3, the only effect of defining
558 .BR _REENTRANT
559 has been to enable one or two of the same declarations that
560 are also enabled by defining
561 .BR _POSIX_C_SOURCE
562 with a value of 199606L or greater.
564 .B _REENTRANT
565 is now obsolete.
566 In glibc 2.25 and later, defining
567 .B _REENTRANT
568 is equivalent to defining
569 .B _POSIX_C_SOURCE
570 with the value 199606L.
571 If a higher POSIX conformance level is
572 selected by any other means (such as
573 .B _POSIX_C_SOURCE
574 itself,
575 .BR _XOPEN_SOURCE ,
576 .BR _DEFAULT_SOURCE ,
578 .BR _GNU_SOURCE ),
579 then defining
580 .B _REENTRANT
581 has no effect.
583 This macro is automatically defined if one compiles with
584 .IR "cc\ \-pthread" .
586 .B _THREAD_SAFE
587 Synonym for the (deprecated)
588 .BR _REENTRANT ,
589 provided for compatibility with some other implementations.
591 .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
592 .\" For more detail, see:
593 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
594 .\" [PATCH] Object size checking to prevent (some) buffer overflows
595 .\" * From: Jakub Jelinek <jakub at redhat dot com>
596 .\" * To: gcc-patches at gcc dot gnu dot org
597 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
598 Defining this macro causes some lightweight checks to be performed
599 to detect some buffer overflow errors when employing
600 various string and memory manipulation functions (for example,
601 .BR memcpy (3),
602 .BR memset (3),
603 .BR stpcpy (3),
604 .BR strcpy (3),
605 .BR strncpy (3),
606 .BR strcat (3),
607 .BR strncat (3),
608 .BR sprintf (3),
609 .BR snprintf (3),
610 .BR vsprintf (3),
611 .BR vsnprintf (3),
612 .BR gets (3),
613 and wide character variants thereof).
614 For some functions, argument consistency is checked;
615 for example, a check is made that
616 .BR open (2)
617 has been supplied with a
618 .I mode
619 argument when the specified flags include
620 .BR O_CREAT .
621 Not all problems are detected, just some common cases.
622 .\" Look for __USE_FORTIFY_LEVEL in the header files
625 .B _FORTIFY_SOURCE
626 is set to 1, with compiler optimization level 1
627 .RI ( "gcc\ \-O1" )
628 and above, checks that shouldn't change the behavior of
629 conforming programs are performed.
630 With
631 .B _FORTIFY_SOURCE
632 set to 2, some more checking is added, but
633 some conforming programs might fail.
634 .\" For example, given the following code
635 .\"        int d;
636 .\"        char buf[1000], buf[1000];
637 .\"        strcpy(fmt, "Hello world\n%n");
638 .\"        snprintf(buf, sizeof(buf), fmt, &d);
640 .\" Compiling with "gcc -D_FORTIFY_SOURCE=2 -O1" and then running will
641 .\" cause the following diagnostic at run time at the snprintf() call
643 .\"        *** %n in writable segment detected ***
644 .\"        Aborted (core dumped)
647 Some of the checks can be performed at compile time
648 (via macros logic implemented in header files),
649 and result in compiler warnings;
650 other checks take place at run time,
651 and result in a run-time error if the check fails.
653 Use of this macro requires compiler support, available with
654 .BR gcc (1)
655 since version 4.0.
656 .SS Default definitions, implicit definitions, and combining definitions
657 If no feature test macros are explicitly defined,
658 then the following feature test macros are defined by default:
659 .BR _BSD_SOURCE
660 (in glibc 2.19 and earlier),
661 .BR _SVID_SOURCE
662 (in glibc 2.19 and earlier),
663 .BR _DEFAULT_SOURCE
664 (since glibc 2.19),
665 .BR _POSIX_SOURCE ,
667 .BR _POSIX_C_SOURCE =200809L
668 (200112L in glibc versions before 2.10;
669 199506L in glibc versions before 2.4;
670 199309L in glibc versions before 2.1).
672 If any of
673 .BR __STRICT_ANSI__ ,
674 .BR _ISOC99_SOURCE ,
675 .BR _ISOC11_SOURCE
676 (since glibc 2.18),
677 .BR _POSIX_SOURCE ,
678 .BR _POSIX_C_SOURCE  ,
679 .BR _XOPEN_SOURCE ,
680 .BR _XOPEN_SOURCE_EXTENDED
681 (in glibc 2.11 and earlier),
682 .BR _BSD_SOURCE
683 (in glibc 2.19 and earlier),
685 .B _SVID_SOURCE
686 (in glibc 2.19 and earlier)
687 is explicitly defined, then
688 .BR _BSD_SOURCE ,
689 .BR _SVID_SOURCE ,
691 .BR _DEFAULT_SOURCE
692 are not defined by default.
695 .B _POSIX_SOURCE
697 .B _POSIX_C_SOURCE
698 are not explicitly defined,
699 and either
700 .B __STRICT_ANSI__
701 is not defined or
702 .B _XOPEN_SOURCE
703 is defined with a value of 500 or more, then
704 .IP * 3
705 .B _POSIX_SOURCE
706 is defined with the value 1; and
707 .IP *
708 .B _POSIX_C_SOURCE
709 is defined with one of the following values:
710 .RS 3
711 .IP \(bu 3
714 .B _XOPEN_SOURCE
715 is defined with a value less than 500;
716 .IP \(bu
717 199506L,
719 .B _XOPEN_SOURCE
720 is defined with a value greater than or equal to 500 and less than 600;
722 .IP \(bu
723 (since glibc 2.4) 200112L,
725 .B _XOPEN_SOURCE
726 is defined with a value greater than or equal to 600 and less than 700.
727 .IP \(bu
728 (Since glibc 2.10)
729 200809L,
731 .B _XOPEN_SOURCE
732 is defined with a value greater than or equal to 700.
733 .IP \(bu
734 Older versions of glibc do not know about the values
735 200112L and 200809L for
736 .BR _POSIX_C_SOURCE ,
737 and the setting of this macro will depend on the glibc version.
738 .IP \(bu
740 .B _XOPEN_SOURCE
741 is undefined, then the setting of
742 .B _POSIX_C_SOURCE
743 depends on the glibc version:
744 199506L, in glibc versions before 2.4;
745 200112L, in glibc 2.4 to 2.9; and
746 200809L, since glibc 2.10.
749 Multiple macros can be defined; the results are additive.
750 .SH CONFORMING TO
751 POSIX.1 specifies
752 .BR _POSIX_C_SOURCE ,
753 .BR _POSIX_SOURCE ,
755 .BR _XOPEN_SOURCE .
757 .B _XOPEN_SOURCE_EXTENDED
758 was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later.
759 .B _FILE_OFFSET_BITS
760 is not specified by any standard,
761 but is employed on some other implementations.
763 .BR _BSD_SOURCE ,
764 .BR _SVID_SOURCE ,
765 .BR _DEFAULT_SOURCE ,
766 .BR _ATFILE_SOURCE ,
767 .BR _GNU_SOURCE ,
768 .BR _FORTIFY_SOURCE ,
769 .BR _REENTRANT ,
771 .B _THREAD_SAFE
772 are specific to Linux (glibc).
773 .SH NOTES
774 .I <features.h>
775 is a Linux/glibc-specific header file.
776 Other systems have an analogous file, but typically with a different name.
777 This header file is automatically included by other header files as
778 required: it is not necessary to explicitly include it in order to
779 employ feature test macros.
781 According to which of the above feature test macros are defined,
782 .I <features.h>
783 internally defines various other macros that are checked by
784 other glibc header files.
785 These macros have names prefixed by two underscores (e.g.,
786 .BR __USE_MISC ).
787 Programs should
788 .I never
789 define these macros directly:
790 instead, the appropriate feature test macro(s) from the
791 list above should be employed.
792 .SH EXAMPLES
793 The program below can be used to explore how the various
794 feature test macros are set depending on the glibc version
795 and what feature test macros are explicitly set.
796 The following shell session, on a system with glibc 2.10,
797 shows some examples of what we would see:
799 .in +4n
801 $ \fBcc ftm.c\fP
802 $ \fB./a.out\fP
803 _POSIX_SOURCE defined
804 _POSIX_C_SOURCE defined: 200809L
805 _BSD_SOURCE defined
806 _SVID_SOURCE defined
807 _ATFILE_SOURCE defined
808 $ \fBcc \-D_XOPEN_SOURCE=500 ftm.c\fP
809 $ \fB./a.out\fP
810 _POSIX_SOURCE defined
811 _POSIX_C_SOURCE defined: 199506L
812 _XOPEN_SOURCE defined: 500
813 $ \fBcc \-D_GNU_SOURCE ftm.c\fP
814 $ \fB./a.out\fP
815 _POSIX_SOURCE defined
816 _POSIX_C_SOURCE defined: 200809L
817 _ISOC99_SOURCE defined
818 _XOPEN_SOURCE defined: 700
819 _XOPEN_SOURCE_EXTENDED defined
820 _LARGEFILE64_SOURCE defined
821 _BSD_SOURCE defined
822 _SVID_SOURCE defined
823 _ATFILE_SOURCE defined
824 _GNU_SOURCE defined
827 .SS Program source
830 /* ftm.c */
832 #include <stdint.h>
833 #include <stdio.h>
834 #include <unistd.h>
835 #include <stdlib.h>
838 main(int argc, char *argv[])
840 #ifdef _POSIX_SOURCE
841     printf("_POSIX_SOURCE defined\en");
842 #endif
844 #ifdef _POSIX_C_SOURCE
845     printf("_POSIX_C_SOURCE defined: %jdL\en",
846             (intmax_t) _POSIX_C_SOURCE);
847 #endif
849 #ifdef _ISOC99_SOURCE
850     printf("_ISOC99_SOURCE defined\en");
851 #endif
853 #ifdef _ISOC11_SOURCE
854     printf("_ISOC11_SOURCE defined\en");
855 #endif
857 #ifdef _XOPEN_SOURCE
858     printf("_XOPEN_SOURCE defined: %d\en", _XOPEN_SOURCE);
859 #endif
861 #ifdef _XOPEN_SOURCE_EXTENDED
862     printf("_XOPEN_SOURCE_EXTENDED defined\en");
863 #endif
865 #ifdef _LARGEFILE64_SOURCE
866     printf("_LARGEFILE64_SOURCE defined\en");
867 #endif
869 #ifdef _FILE_OFFSET_BITS
870     printf("_FILE_OFFSET_BITS defined: %d\en", _FILE_OFFSET_BITS);
871 #endif
873 #ifdef _BSD_SOURCE
874     printf("_BSD_SOURCE defined\en");
875 #endif
877 #ifdef _SVID_SOURCE
878     printf("_SVID_SOURCE defined\en");
879 #endif
881 #ifdef _DEFAULT_SOURCE
882     printf("_DEFAULT_SOURCE defined\en");
883 #endif
885 #ifdef _ATFILE_SOURCE
886     printf("_ATFILE_SOURCE defined\en");
887 #endif
889 #ifdef _GNU_SOURCE
890     printf("_GNU_SOURCE defined\en");
891 #endif
893 #ifdef _REENTRANT
894     printf("_REENTRANT defined\en");
895 #endif
897 #ifdef _THREAD_SAFE
898     printf("_THREAD_SAFE defined\en");
899 #endif
901 #ifdef _FORTIFY_SOURCE
902     printf("_FORTIFY_SOURCE defined\en");
903 #endif
905     exit(EXIT_SUCCESS);
908 .SH SEE ALSO
909 .BR libc (7),
910 .BR standards (7),
911 .BR system_data_types (7)
913 The section "Feature Test Macros" under
914 .IR "info libc" .
915 .\" But beware: the info libc document is out of date (Jul 07, mtk)
917 .I /usr/include/features.h