]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/feature_test_macros.7
sched.7: Add nice(2), getpriority(2), and setpriority(2) to API list
[thirdparty/man-pages.git] / man7 / feature_test_macros.7
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 2016-07-17 "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
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
40 Some feature test macros are useful for creating portable applications,
41 by preventing nonstandard definitions from being exposed.
42 Other macros can be used to expose nonstandard definitions that
43 are not exposed by default.
44
45 The precise effects of each of the feature test macros described below
46 can be ascertained by inspecting the
47 .I <features.h>
48 header file.
49 .BR Note :
50 applications do
51 .I not
52 need to directly include
53 .IR <features.h> ;
54 indeed, doing so is actively discouraged.
55 See NOTES.
56 .SS Specification of feature test macro requirements in manual pages
57 When a function requires that a feature test macro is defined,
58 the manual page SYNOPSIS typically includes a note of the following form
59 (this example from the
60 .BR acct (2)
61 manual page):
62 .RS 8
63 .sp
64 .B #include <unistd.h>
65 .sp
66 .BI "int acct(const char *" filename );
67 .sp
68 .nf
69 .in -4n
70 Feature Test Macro Requirements for glibc (see
71 .BR feature_test_macros (7)):
72 .fi
73 .in
74 .sp
75 .BR acct ():
76 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
77 .RE
78 .PP
79 The
80 .B ||
81 means that in order to obtain the declaration of
82 .BR acct (2)
83 from
84 .IR <unistd.h> ,
85 .I either
86 of the following macro
87 definitions must be made before including any header files:
88 .RS
89 .nf
90
91 #define _BSD_SOURCE
92 #define _XOPEN_SOURCE /* or any value < 500 */
93 .fi
94 .RE
95 .PP
96 Alternatively, equivalent definitions can be included in the
97 compilation command:
98 .RS
99 .nf
100
101 cc \-D_BSD_SOURCE
102 cc \-D_XOPEN_SOURCE # Or any value < 500
103 .fi
104 .RE
105 .PP
106 Note that, as described below,
107 .BR "some feature test macros are defined by default" ,
108 so that it may not always be necessary to
109 explicitly specify the feature test macro(s) shown in the
110 SYNOPSIS.
111
112 In a few cases, manual pages use a shorthand for expressing the
113 feature test macro requirements (this example from
114 .BR readahead (2)):
115 .RS
116 .nf
117
118 .B #define _GNU_SOURCE
119 .B #include <fcntl.h>
120 .sp
121 .BI "ssize_t readahead(int " fd ", off64_t *" offset ", size_t " count );
122 .fi
123 .RE
124 .PP
125 This format is employed in cases where only a single
126 feature test macro can be used to expose the function
127 declaration, and that macro is not defined by default.
128 .SS Feature test macros understood by glibc
129 The paragraphs below explain how feature test macros are handled
130 in Linux glibc 2.\fIx\fP,
131 .I x
132 > 0.
133
134 First, though a summary of a few details for the impatient:
135 .IP * 3
136 The macros that you most likely need to use in modern source code are
137 .BR _POSIX_C_SOURCE
138 (for definitions from various versions of POSIX.1),
139 .BR _XOPEN_SOURCE
140 (for definitions from various versions of SUS),
141 .BR _GNU_SOURCE
142 (for GNU and/or Linux specific stuff), and
143 .BR _DEFAULT_SOURCE
144 (to get definitions that would normally be provided by default).
145 .IP *
146 Certain macros are defined with default values.
147 Thus, although one or more macros may be indicated as being
148 required in the SYNOPSIS of a man page,
149 it may not be necessary to define them explicitly.
150 Full details of the defaults are given later in this man page.
151 .IP *
152 Defining
153 .BR _XOPEN_SOURCE
154 with a value of 600 or greater produces the same effects as defining
155 .BR _POSIX_C_SOURCE
156 with a value of 200112L or greater.
157 Where one sees
158 .RS
159 .nf
160
161 _POSIX_C_SOURCE >= 200112L
162
163 .fi
164 .RE
165 .IP
166 in the feature test macro requirements in the SYNOPSIS of a man page,
167 it is implicit that the following has the same effect:
168 .RS
169 .nf
170
171 _XOPEN_SOURCE >= 600
172
173 .fi
174 .RE
175 .IP *
176 Defining
177 .BR _XOPEN_SOURCE
178 with a value of 700 or greater produces the same effects as defining
179 .BR _POSIX_C_SOURCE
180 with a value of 200809L or greater.
181 Where one sees
182 .RS
183 .nf
184
185 _POSIX_C_SOURCE >= 200809L
186
187 .fi
188 .RE
189 .IP
190 in the feature test macro requirements in the SYNOPSIS of a man page,
191 it is implicit that the following has the same effect:
192 .RS
193 .nf
194
195 _XOPEN_SOURCE >= 700
196
197 .fi
198 .RE
199 .\" The details in glibc 2.0 are simpler, but combining a
200 .\" a description of them with the details in later glibc versions
201 .\" would make for a complicated description.
202
203 Linux glibc understands the following feature test macros:
204 .TP
205 .B __STRICT_ANSI__
206 ISO Standard C.
207 This macro is implicitly defined by
208 .BR gcc (1)
209 when invoked with, for example, the
210 .I -std=c99
211 or
212 .I -ansi
213 flag.
214 .TP
215 .B _POSIX_C_SOURCE
216 Defining this macro causes header files to expose definitions as follows:
217 .RS
218 .IP \(bu 3
219 The value 1 exposes definitions conforming to POSIX.1-1990 and
220 ISO C (1990).
221 .IP \(bu
222 The value 2 or greater additionally exposes
223 definitions for POSIX.2-1992.
224 .IP \(bu
225 The value 199309L or greater additionally exposes
226 definitions for POSIX.1b (real-time extensions).
227 .\" 199506L functionality is available only since glibc 2.1
228 .IP \(bu
229 The value 199506L or greater additionally exposes
230 definitions for POSIX.1c (threads).
231 .IP \(bu
232 (Since glibc 2.3.3)
233 The value 200112L or greater additionally exposes definitions corresponding
234 to the POSIX.1-2001 base specification (excluding the XSI extension).
235 This value also causes C95 (since glibc 2.12) and
236 C99 (since glibc 2.10) features to be exposed
237 (in other words, the equivalent of defining
238 .BR _ISOC99_SOURCE ).
239 .IP \(bu
240 (Since glibc 2.10)
241 The value 200809L or greater additionally exposes definitions corresponding
242 to the POSIX.1-2008 base specification (excluding the XSI extension).
243 .RE
244 .TP
245 .B _POSIX_SOURCE
246 Defining this obsolete macro with any value is equivalent to defining
247 .B _POSIX_C_SOURCE
248 with the value 1.
249
250 Since this macro is obsolete,
251 its usage is generally not documented when discussing
252 feature test macro requirements in the man pages.
253 .TP
254 .B _XOPEN_SOURCE
255 Defining this macro causes header files to expose definitions as follows:
256 .RS
257 .IP \(bu 3
258 Defining with any value exposes
259 definitions conforming to POSIX.1, POSIX.2, and XPG4.
260 .IP \(bu
261 The value 500 or greater additionally exposes
262 definitions for SUSv2 (UNIX 98).
263 .IP \(bu
264 (Since glibc 2.2) The value 600 or greater additionally exposes
265 definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
266 plus the XSI extension) and C99 definitions.
267 .IP \(bu
268 (Since glibc 2.10) The value 700 or greater additionally exposes
269 definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
270 plus the XSI extension).
271 .RE
272 .IP
273 If
274 .B __STRICT_ANSI__
275 is not defined, or
276 .BR _XOPEN_SOURCE
277 is defined with a value greater than or equal to 500
278 .I and
279 neither
280 .B _POSIX_SOURCE
281 nor
282 .B _POSIX_C_SOURCE
283 is explicitly defined, then
284 the following macros are implicitly defined:
285 .RS
286 .IP \(bu 3
287 .B _POSIX_SOURCE
288 is defined with the value 1.
289 .IP \(bu
290 .B _POSIX_C_SOURCE
291 is defined, according to the value of
292 .BR _XOPEN_SOURCE :
293 .RS 7
294 .TP
295 .BR _XOPEN_SOURCE " < 500"
296 .B _POSIX_C_SOURCE
297 is defined with the value 2.
298 .TP
299 .RB "500 <= " _XOPEN_SOURCE " < 600"
300 .B _POSIX_C_SOURCE
301 is defined with the value 199506L.
302 .TP
303 .RB "600 <= " _XOPEN_SOURCE " < 700"
304 .B _POSIX_C_SOURCE
305 is defined with the value 200112L.
306 .TP
307 .RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
308 .B _POSIX_C_SOURCE
309 is defined with the value 200809L.
310 .RE
311 .RE
312 .IP
313 In addition, defining
314 .BR _XOPEN_SOURCE
315 with a value of 500 or greater produces the same effects as defining
316 .BR _XOPEN_SOURCE_EXTENDED .
317 .TP
318 .B _XOPEN_SOURCE_EXTENDED
319 If this macro is defined,
320 .I and
321 .B _XOPEN_SOURCE
322 is defined, then expose definitions corresponding to the XPG4v2
323 (SUSv1) UNIX extensions (UNIX 95).
324 Defining
325 .B _XOPEN_SOURCE
326 with a value of 500 or more also produces the same effect as defining
327 .BR _XOPEN_SOURCE_EXTENDED .
328 Use of
329 .BR _XOPEN_SOURCE_EXTENDED
330 in new source code should be avoided.
331
332 Since defining
333 .B _XOPEN_SOURCE
334 with a value of 500 or more has the same effect as defining
335 .BR _XOPEN_SOURCE_EXTENDED ,
336 the latter (obsolete) feature test macro is generally not described in the
337 SYNOPSIS in man pages.
338 .TP
339 .BR _ISOC99_SOURCE " (since glibc 2.1.3)"
340 Exposes declarations consistent with the ISO C99 standard.
341
342 Earlier glibc 2.1.x versions recognized an equivalent macro named
343 .B _ISOC9X_SOURCE
344 (because the C99 standard had not then been finalized).
345 Although the use of this macro is obsolete, glibc continues
346 to recognize it for backward compatibility.
347
348 Defining
349 .B _ISOC99_SOURCE
350 also exposes ISO C (1990) Amendment 1 ("C95") definitions.
351 (The primary change in C95 was support for international character sets.)
352
353 Invoking the C compiler with the option
354 .IR \-std=c99
355 produces the same effects as defining this macro.
356 .TP
357 .BR _ISOC11_SOURCE " (since glibc 2.16)"
358 Exposes declarations consistent with the ISO C11 standard.
359 Defining this macro also enables C99 and C95 features (like
360 .BR _ISOC99_SOURCE ).
361
362 Invoking the C compiler with the option
363 .IR \-std=c11
364 produces the same effects as defining this macro.
365 .TP
366 .B _LARGEFILE64_SOURCE
367 Expose definitions for the alternative API specified by the
368 LFS (Large File Summit) as a "transitional extension" to the
369 Single UNIX Specification.
370 (See
371 .UR http:\:/\:/opengroup.org\:/platform\:/lfs.html
372 .UE .)
373 The alternative API consists of a set of new objects
374 (i.e., functions and types) whose names are suffixed with "64"
375 (e.g.,
376 .I off64_t
377 versus
378 .IR off_t ,
379 .BR lseek64 ()
380 versus
381 .BR lseek (),
382 etc.).
383 New programs should not employ this macro; instead
384 .I _FILE_OFFSET_BITS=64
385 should be employed.
386 .TP
387 .BR _LARGEFILE_SOURCE
388 This macro was historically used to expose certain functions (specifically
389 .BR fseeko (3)
390 and
391 .BR ftello (3))
392 that address limitations of earlier APIs
393 .RB ( fseek (3)
394 and
395 .BR ftell (3))
396 that use
397 .IR "long int"
398 for file offsets.
399 This macro is implicitly defined if
400 .BR _XOPEN_SOURCE
401 is defined with a value greater than or equal to 500.
402 New programs should not employ this macro;
403 defining
404 .BR _XOPEN_SOURCE
405 as just described or defining
406 .B _FILE_OFFSET_BITS
407 with the value 64 is the preferred mechanism to achieve the same result.
408 .TP
409 .B _FILE_OFFSET_BITS
410 Defining this macro with the value 64
411 automatically converts references to 32-bit functions and data types
412 related to file I/O and filesystem operations into references to
413 their 64-bit counterparts.
414 This is useful for performing I/O on large files (> 2 Gigabytes)
415 on 32-bit systems.
416 (Defining this macro permits correctly written programs to use
417 large files with only a recompilation being required.)
418
419 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
420 and on those systems this macro has no effect.
421 .TP
422 .BR _BSD_SOURCE " (deprecated since glibc 2.20)"
423 Defining this macro with any value causes header files to expose
424 BSD-derived definitions.
425
426 In glibc versions up to and including 2.18,
427 defining this macro also causes BSD definitions to be preferred in
428 some situations where standards conflict, unless one or more of
429 .BR _SVID_SOURCE ,
430 .BR _POSIX_SOURCE ,
431 .BR _POSIX_C_SOURCE ,
432 .BR _XOPEN_SOURCE ,
433 .BR _XOPEN_SOURCE_EXTENDED ,
434 or
435 .B _GNU_SOURCE
436 is defined, in which case BSD definitions are disfavored.
437 Since glibc 2.19,
438 .B _BSD_SOURCE
439 no longer causes BSD definitions to be preferred in case of conflicts.
440
441 Since glibc 2.20, this macro is deprecated.
442 .\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
443 .\" commit 498afc54dfee41d33ba519f496e96480badace8e
444 .\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
445 It now has the same effect as defining
446 .BR _DEFAULT_SOURCE ,
447 but generates a compile-time warning (unless
448 .BR _DEFAULT_SOURCE
449 .\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
450 is also defined).
451 Use
452 .B _DEFAULT_SOURCE
453 instead.
454 To allow code that requires
455 .BR _BSD_SOURCE
456 in glibc 2.19 and earlier and
457 .BR _DEFAULT_SOURCE
458 in glibc 2.20 and later to compile without warnings, define
459 .I both
460 .B _BSD_SOURCE
461 and
462 .BR _DEFAULT_SOURCE .
463 .TP
464 .BR _SVID_SOURCE " (deprecated since glibc 2.20)"
465 Defining this macro with any value causes header files to expose
466 System V-derived definitions.
467 (SVID == System V Interface Definition; see
468 .BR standards (7).)
469
470 Since glibc 2.20, this macro is deprecated in the same fashion as
471 .BR _BSD_SOURCE .
472 .TP
473 .BR _DEFAULT_SOURCE " (since glibc 2.19)"
474 This macro can be defined to ensure that the "default"
475 definitions are provided even when the defaults would otherwise
476 be disabled,
477 as happens when individual macros are explicitly defined,
478 or the compiler is invoked in one of its "standard" modes (e.g.,
479 .IR "cc\ \-std=c99" ).
480 Defining
481 .B _DEFAULT_SOURCE
482 without defining other individual macros
483 or invoking the compiler in one of its "standard" modes has no effect.
484
485 The "default" definitions comprise those required by POSIX.1-2008 and ISO C99,
486 as well as various definitions originally derived from BSD and System V.
487 On glibc 2.19 and earlier, these defaults were approximately equivalent
488 to explicitly defining the following:
489
490 cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
491 .TP
492 .BR _ATFILE_SOURCE " (since glibc 2.4)"
493 Defining this macro with any value causes header files to expose
494 declarations of a range of functions with the suffix "at";
495 see
496 .BR openat (2).
497 Since glibc 2.10, this macro is also implicitly defined if
498 .BR _POSIX_C_SOURCE
499 is defined with a value greater than or equal to 200809L.
500 .TP
501 .B _GNU_SOURCE
502 Defining this macro (with any value) implicitly defines
503 .BR _ATFILE_SOURCE ,
504 .BR _LARGEFILE64_SOURCE ,
505 .BR _ISOC99_SOURCE ,
506 .BR _XOPEN_SOURCE_EXTENDED ,
507 .BR _POSIX_SOURCE ,
508 .B _POSIX_C_SOURCE
509 with the value 200809L
510 (200112L in glibc versions before 2.10;
511 199506L in glibc versions before 2.5;
512 199309L in glibc versions before 2.1)
513 and
514 .B _XOPEN_SOURCE
515 with the value 700
516 (600 in glibc versions before 2.10;
517 500 in glibc versions before 2.2).
518 In addition, various GNU-specific extensions are also exposed.
519
520 Since glibc 2.19, defining
521 .BR _GNU_SOURCE
522 also has the effect of implicitly defining
523 .BR _DEFAULT_SOURCE .
524 In glibc versions before 2.20, defining
525 .BR _GNU_SOURCE
526 also had the effect of implicitly defining
527 .BR _BSD_SOURCE
528 and
529 .BR _SVID_SOURCE .
530 .TP
531 .B _REENTRANT
532 Defining this macro exposes definitions of certain reentrant functions.
533 For multithreaded programs, use
534 .I "cc\ \-pthread"
535 instead.
536 .TP
537 .B _THREAD_SAFE
538 Synonym for
539 .BR _REENTRANT ,
540 provided for compatibility with some other implementations.
541 .TP
542 .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
543 .\" For more detail, see:
544 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
545 .\" [PATCH] Object size checking to prevent (some) buffer overflows
546 .\" * From: Jakub Jelinek <jakub at redhat dot com>
547 .\" * To: gcc-patches at gcc dot gnu dot org
548 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
549 Defining this macro causes some lightweight checks to be performed
550 to detect some buffer overflow errors when employing
551 various string and memory manipulation functions (for example,
552 .BR memcpy (3),
553 .BR memset (3),
554 .BR stpcpy (3),
555 .BR strcpy (3),
556 .BR strncpy (3),
557 .BR strcat (3),
558 .BR strncat (3),
559 .BR sprintf (3),
560 .BR snprintf (3),
561 .BR vsprintf (3),
562 .BR vsnprintf (3),
563 .BR gets (3),
564 and wide character variants thereof).
565 For some functions, argument consistency is checked;
566 for example, a check is made that
567 .BR open (2)
568 has been supplied with a
569 .I mode
570 argument when the specified flags include
571 .BR O_CREAT .
572 Not all problems are detected, just some common cases.
573 .\" Look for __USE_FORTIFY_LEVEL in the header files
574
575 If
576 .B _FORTIFY_SOURCE
577 is set to 1, with compiler optimization level 1
578 .RI ( "gcc\ \-O1" )
579 and above, checks that shouldn't change the behavior of
580 conforming programs are performed.
581 With
582 .B _FORTIFY_SOURCE
583 set to 2, some more checking is added, but
584 some conforming programs might fail.
585 .\" For example, given the following code
586 .\" int d;
587 .\" char buf[1000], buf[1000];
588 .\" strcpy(fmt, "Hello world\n%n");
589 .\" snprintf(buf, sizeof(buf), fmt, &d);
590 .\"
591 .\" Compiling with "gcc -D_FORTIFY_SOURCE=2 -O1" and then running will
592 .\" cause the following diagnostic at runtime at the snprintf() call
593 .\"
594 .\" *** %n in writable segment detected ***
595 .\" Aborted (core dumped)
596 .\"
597
598 Some of the checks can be performed at compile time
599 (via macros logic implemented in header files),
600 and result in compiler warnings;
601 other checks take place at run time,
602 and result in a run-time error if the check fails.
603
604 Use of this macro requires compiler support, available with
605 .BR gcc (1)
606 since version 4.0.
607 .SS Default definitions, implicit definitions, and combining definitions
608 .PP
609 If no feature test macros are explicitly defined,
610 then the following feature test macros are defined by default:
611 .BR _BSD_SOURCE
612 (in glibc 2.19 and earlier),
613 .BR _SVID_SOURCE
614 (in glibc 2.19 and earlier),
615 .BR _DEFAULT_SOURCE
616 (since glibc 2.19),
617 .BR _POSIX_SOURCE ,
618 and
619 .BR _POSIX_C_SOURCE =200809L
620 (200112L in glibc versions before 2.10;
621 199506L in glibc versions before 2.4;
622 199309L in glibc versions before 2.1).
623 .PP
624 If any of
625 .BR __STRICT_ANSI__ ,
626 .BR _ISOC99_SOURCE ,
627 .BR _POSIX_SOURCE ,
628 .BR _POSIX_C_SOURCE ,
629 .BR _XOPEN_SOURCE ,
630 .BR _XOPEN_SOURCE_EXTENDED ,
631 .BR _BSD_SOURCE
632 (in glibc 2.19 and earlier),
633 or
634 .B _SVID_SOURCE
635 (in glibc 2.19 and earlier)
636 is explicitly defined, then
637 .BR _BSD_SOURCE ,
638 .BR _SVID_SOURCE ,
639 and
640 .BR _DEFAULT_SOURCE
641 are not defined by default.
642
643 If
644 .B _POSIX_SOURCE
645 and
646 .B _POSIX_C_SOURCE
647 are not explicitly defined,
648 and either
649 .B __STRICT_ANSI__
650 is not defined or
651 .B _XOPEN_SOURCE
652 is defined with a value of 500 or more, then
653 .IP * 3
654 .B _POSIX_SOURCE
655 is defined with the value 1; and
656 .IP *
657 .B _POSIX_C_SOURCE
658 is defined with one of the following values:
659 .RS 3
660 .IP \(bu 3
661 2,
662 if
663 .B _XOPEN_SOURCE
664 is defined with a value less than 500;
665 .IP \(bu
666 199506L,
667 if
668 .B _XOPEN_SOURCE
669 is defined with a value greater than or equal to 500 and less than 600;
670 or
671 .IP \(bu
672 (since glibc 2.4) 200112L,
673 if
674 .B _XOPEN_SOURCE
675 is defined with a value greater than or equal to 600 and less than 700.
676 .IP \(bu
677 (Since glibc 2.10)
678 200809L,
679 if
680 .B _XOPEN_SOURCE
681 is defined with a value greater than or equal to 700.
682 .IP \(bu
683 Older versions of glibc do not know about the values
684 200112L and 200809L for
685 .BR _POSIX_C_SOURCE ,
686 and the setting of this macro will depend on the glibc version.
687 .IP \(bu
688 If
689 .B _XOPEN_SOURCE
690 is undefined, then the setting of
691 .B _POSIX_C_SOURCE
692 depends on the glibc version:
693 199506L, in glibc versions before 2.4;
694 200112L, in glibc 2.4 to 2.9; and
695 200809L, since glibc 2.10.
696 .RE
697 .PP
698 Multiple macros can be defined; the results are additive.
699 .SH CONFORMING TO
700 POSIX.1 specifies
701 .BR _POSIX_C_SOURCE ,
702 .BR _POSIX_SOURCE ,
703 and
704 .BR _XOPEN_SOURCE .
705
706 .B _XOPEN_SOURCE_EXTENDED
707 was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later.
708 .B _FILE_OFFSET_BITS
709 is not specified by any standard,
710 but is employed on some other implementations.
711
712 .BR _BSD_SOURCE ,
713 .BR _SVID_SOURCE ,
714 .BR _DEFAULT_SOURCE ,
715 .BR _ATFILE_SOURCE ,
716 .BR _GNU_SOURCE ,
717 .BR _FORTIFY_SOURCE ,
718 .BR _REENTRANT ,
719 and
720 .B _THREAD_SAFE
721 are specific to Linux (glibc).
722 .SH NOTES
723 .I <features.h>
724 is a Linux/glibc-specific header file.
725 Other systems have an analogous file, but typically with a different name.
726 This header file is automatically included by other header files as
727 required: it is not necessary to explicitly include it in order to
728 employ feature test macros.
729
730 According to which of the above feature test macros are defined,
731 .I <features.h>
732 internally defines various other macros that are checked by
733 other glibc header files.
734 These macros have names prefixed by two underscores (e.g.,
735 .BR __USE_MISC ).
736 Programs should
737 .I never
738 define these macros directly:
739 instead, the appropriate feature test macro(s) from the
740 list above should be employed.
741 .SH EXAMPLE
742 The program below can be used to explore how the various
743 feature test macros are set depending on the glibc version
744 and what feature test macros are explicitly set.
745 The following shell session, on a system with glibc 2.10,
746 shows some examples of what we would see:
747 .in +4n
748 .nf
749
750 $ \fBcc ftm.c\fP
751 $ \fB./a.out\fP
752 _POSIX_SOURCE defined
753 _POSIX_C_SOURCE defined: 200809L
754 _BSD_SOURCE defined
755 _SVID_SOURCE defined
756 _ATFILE_SOURCE defined
757 $ \fBcc \-D_XOPEN_SOURCE=500 ftm.c\fP
758 $ \fB./a.out\fP
759 _POSIX_SOURCE defined
760 _POSIX_C_SOURCE defined: 199506L
761 _XOPEN_SOURCE defined: 500
762 $ \fBcc \-D_GNU_SOURCE ftm.c\fP
763 $ \fB./a.out\fP
764 _POSIX_SOURCE defined
765 _POSIX_C_SOURCE defined: 200809L
766 _ISOC99_SOURCE defined
767 _XOPEN_SOURCE defined: 700
768 _XOPEN_SOURCE_EXTENDED defined
769 _LARGEFILE64_SOURCE defined
770 _BSD_SOURCE defined
771 _SVID_SOURCE defined
772 _ATFILE_SOURCE defined
773 _GNU_SOURCE defined
774 .fi
775 .in
776 .SS Program source
777 \&
778 .nf
779 /* ftm.c */
780
781 #include <stdio.h>
782 #include <unistd.h>
783 #include <stdlib.h>
784
785 int
786 main(int argc, char *argv[])
787 {
788 #ifdef _POSIX_SOURCE
789 printf("_POSIX_SOURCE defined\\n");
790 #endif
791
792 #ifdef _POSIX_C_SOURCE
793 printf("_POSIX_C_SOURCE defined: %ldL\\n", (long) _POSIX_C_SOURCE);
794 #endif
795
796 #ifdef _ISOC99_SOURCE
797 printf("_ISOC99_SOURCE defined\\n");
798 #endif
799
800 #ifdef _ISOC11_SOURCE
801 printf("_ISOC11_SOURCE defined\\n");
802 #endif
803
804 #ifdef _XOPEN_SOURCE
805 printf("_XOPEN_SOURCE defined: %d\\n", _XOPEN_SOURCE);
806 #endif
807
808 #ifdef _XOPEN_SOURCE_EXTENDED
809 printf("_XOPEN_SOURCE_EXTENDED defined\\n");
810 #endif
811
812 #ifdef _LARGEFILE64_SOURCE
813 printf("_LARGEFILE64_SOURCE defined\\n");
814 #endif
815
816 #ifdef _FILE_OFFSET_BITS
817 printf("_FILE_OFFSET_BITS defined: %d\\n", _FILE_OFFSET_BITS);
818 #endif
819
820 #ifdef _BSD_SOURCE
821 printf("_BSD_SOURCE defined\\n");
822 #endif
823
824 #ifdef _SVID_SOURCE
825 printf("_SVID_SOURCE defined\\n");
826 #endif
827
828 #ifdef _DEFAULT_SOURCE
829 printf("_DEFAULT_SOURCE defined\\n");
830 #endif
831
832 #ifdef _ATFILE_SOURCE
833 printf("_ATFILE_SOURCE defined\\n");
834 #endif
835
836 #ifdef _GNU_SOURCE
837 printf("_GNU_SOURCE defined\\n");
838 #endif
839
840 #ifdef _REENTRANT
841 printf("_REENTRANT defined\\n");
842 #endif
843
844 #ifdef _THREAD_SAFE
845 printf("_THREAD_SAFE defined\\n");
846 #endif
847
848 #ifdef _FORTIFY_SOURCE
849 printf("_FORTIFY_SOURCE defined\\n");
850 #endif
851
852 exit(EXIT_SUCCESS);
853 }
854 .fi
855 .SH SEE ALSO
856 .BR libc (7),
857 .BR standards (7)
858
859 The section "Feature Test Macros" under
860 .IR "info libc" .
861 .\" But beware: the info libc document is out of date (Jul 07, mtk)
862
863 .I /usr/include/features.h