feature_test_macros(7) Miscellaneous Information Manual feature_test_macros - . : , . (cc -D=) . - , . , _GNU_SOURCE , ( POSIX ): #include #define _GNU_SOURCE #include ; . , . , , . : -- . . , , ( acct(2)): #include int acct(const char *filename); glibc (. feature_test_macros(7)): acct(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) || , acct(2) : #define _BSD_SOURCE #define _XOPEN_SOURCE /* < 500 */ : cc -D_BSD_SOURCE cc -D_XOPEN_SOURCE # < 500 , , , . ( readahead(2)): #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 #include ssize_t readahead(int fd, off_t *offset, size_t count); This format is employed when the feature test macros ensure that the proper function declarations are visible, and the macros are not defined by default. , glibc The paragraphs below explain how feature test macros are handled in glibc 2.x, x > 0. First, though, a summary of a few details for the impatient: o , , , : _POSIX_C_SOURCE ( POSIX.1), _XOPEN_SOURCE ( SUS), _GNU_SOURCE ( GNU / Linux) _DEFAULT_SOURCE (, , , ). o . , , . . o _XOPEN_SOURCE 600 _POSIX_C_SOURCE 200112L . _POSIX_C_SOURCE >= 200112L , : _XOPEN_SOURCE >= 600 o _XOPEN_SOURCE 700 _POSIX_C_SOURCE 200809L . _POSIX_C_SOURCE >= 200809L , : _XOPEN_SOURCE >= 700 glibc understands the following feature test macros: __STRICT_ANSI__ ISO C. gcc(1), -std=c99 -ansi. _POSIX_C_SOURCE : o 1 , POSIX.1-1990 ISO C (1990). o 2 , POSIX.2-1992. o 199309L , POSIX.1b ( ). o 199506L , POSIX.1c (). o ( glibc 2.3.3) 200112L , POSIX.1-2001 ( XSI) C95 ( glibc 2.12) C99 ( glibc 2.10). _ISOC99_SOURCE. o ( glibc 2.10) 200809L , POSIX.1-2008 ( XSI). _POSIX_SOURCE _POSIX_C_SOURCE 1. , , , . _XOPEN_SOURCE : o , POSIX.1, POSIX.2 XPG4. o 500 , SUSv2 (UNIX 98). o ( glibc 2.2) 600L , SUSv3 (UNIX 03; . ., POSIX.1-2001 XSI), C99. o ( glibc 2.10) 700 , SUSv4 (. ., POSIX.1-2008 XSI). If __STRICT_ANSI__ _XOPEN_SOURCE 500 _POSIX_SOURCE _POSIX_C_SOURCE, : o _POSIX_SOURCE 1. o _POSIX_C_SOURCE _XOPEN_SOURCE: _XOPEN_SOURCE < 500 _POSIX_C_SOURCE 2. 500 <= _XOPEN_SOURCE < 600 _POSIX_C_SOURCE 199506L. 600 <= _XOPEN_SOURCE < 700 _POSIX_C_SOURCE 200112L. 700 <= _XOPEN_SOURCE ( glibc 2.10) _POSIX_C_SOURCE 200809L. , _XOPEN_SOURCE 500 _XOPEN_SOURCE_EXTENDED. _XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE, , UNIX (UNIX 95) XPG4v2 (SUSv1). _XOPEN_SOURCE 500 , _XOPEN_SOURCE_EXTENDED. _XOPEN_SOURCE_EXTENDED . _XOPEN_SOURCE 500 , _XOPEN_SOURCE_EXTENDED, () , , . _ISOC99_SOURCE ( glibc 2.1.3) , ISO C99. glibc 2.1.x - _ISOC9X_SOURCE ( C99 ). , glibc . ISO C (1990) Amendment 1 (<>). C95 . C -std=c99 . _ISOC11_SOURCE ( glibc 2.16) , ISO C11. C99 C95 ( _ISOC99_SOURCE). C -std=c11 . _LARGEFILE64_SOURCE , LFS (Large File Summit) << >> Single UNIX Specification ( (. ., ), <<>>64 (, off64_t off_t, lseek64() lseek(), . .). ; _FILE_OFFSET_BITS=64. _LARGEFILE_SOURCE This macro was historically used to expose certain functions (specifically fseeko(3) and ftello(3)) that address limitations of earlier APIs (fseek(3) and ftell(3)) that use long for file offsets. This macro is implicitly defined if _XOPEN_SOURCE is defined with a value greater than or equal to 500. New programs should not employ this macro; defining _XOPEN_SOURCE as just described or defining _FILE_OFFSET_BITS with the value 64 is the preferred mechanism to achieve the same result. _FILE_OFFSET_BITS Defining this macro with the value 64 automatically converts references to 32-bit functions and data types related to file I/O and filesystem operations into references to their 64-bit counterparts. This is useful for performing I/O on large files (> 2 Gigabytes) on 32-bit systems. It is also useful when calling functions like copy_file_range(2) that were added more recently and that come only in 64-bit flavors. (Defining this macro permits correctly written programs to use large files with only a recompilation being required.) 64- 2 , . _TIME_BITS Defining this macro with the value 64 changes the width of time_t(3type) to 64-bit which allows handling of timestamps beyond 2038. It is closely related to _FILE_OFFSET_BITS and depending on implementation, may require it set. This macro is available as of glibc 2.34. _BSD_SOURCE ( glibc 2.20) BSD. glibc 2.18 BSD , . _SVID_SOURCE, _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED _GNU_SOURCE, BSD . glibc 2.19 _BSD_SOURCE BSD . glibc 2.20 . _DEFAULT_SOURCE, ( _DEFAULT_SOURCE). _DEFAULT_SOURCE . , _BSD_SOURCE glibc 2.19 _DEFAULT_SOURCE glibc 2.20 , _BSD_SOURCE _DEFAULT_SOURCE . _SVID_SOURCE ( glibc 2.20) System V (SVID == System V Interface Definition; standards(7)). glibc 2.20 _BSD_SOURCE. _DEFAULT_SOURCE ( glibc 2.19) This macro can be defined to ensure that the "default" definitions are provided even when the defaults would otherwise be disabled, as happens when individual macros are explicitly defined, or the compiler is invoked in one of its "standard" modes (e.g., cc -std=c99). Defining _DEFAULT_SOURCE without defining other individual macros or invoking the compiler in one of its "standard" modes has no effect. << >> , POSIX.1-2008 ISO C99, BSD System V. glibc 2.19 : cc -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809 _ATFILE_SOURCE ( glibc 2.4) <>; openat(2). glibc 2.10 , _POSIX_C_SOURCE 200809L . _GNU_SOURCE Defining this macro (with any value) implicitly defines _ATFILE_SOURCE, _LARGEFILE64_SOURCE, _ISOC99_SOURCE, _XOPEN_SOURCE_EXTENDED, _POSIX_SOURCE, _POSIX_C_SOURCE with the value 200809L (200112L before glibc 2.10; 199506L before glibc 2.5; 199309L before glibc 2.1) and _XOPEN_SOURCE with the value 700 (600 before glibc 2.10; 500 before glibc 2.2). In addition, various GNU-specific extensions are also exposed. Since glibc 2.19, defining _GNU_SOURCE also has the effect of implicitly defining _DEFAULT_SOURCE. Before glibc 2.20, defining _GNU_SOURCE also had the effect of implicitly defining _BSD_SOURCE and _SVID_SOURCE. _REENTRANT , C, ( C ). glibc . glibc ; glibc 2.3 _REENTRANT , _POSIX_C_SOURCE 199606L . _REENTRANT . glibc 2.25 _REENTRANT _POSIX_C_SOURCE 199606L. POSIX (, _POSIX_C_SOURCE, _XOPEN_SOURCE, _DEFAULT_SOURCE _GNU_SOURCE), _REENTRANT. This macro is automatically defined if one compiles with cc -pthread. _THREAD_SAFE () _REENTRANT, . _FORTIFY_SOURCE ( glibc 2.3.4) , (, memcpy(3), memset(3), stpcpy(3), strcpy(3), strncpy(3), strcat(3), strncat(3), sprintf(3), snprintf(3), vsprintf(3), vsnprintf(3), gets(3) ). ; , , open(2) mode, O_CREAT. , . _FORTIFY_SOURCE 1 1 (gcc -O1) , , . _FORTIFY_SOURCE 2, , . ( , ) ; . With _FORTIFY_SOURCE set to 3, additional checking is added to intercept some function calls used with an argument of variable size where the compiler can deduce an upper bound for its value. For example, a program where malloc(3)'s size argument is variable can now be fortified. Use of this macro requires compiler support, available since gcc 4.0 and clang 2.6. Use of _FORTIFY_SOURCE set to 3 requires gcc 12.0 or later, or clang 9.0 or later, in conjunction with glibc 2.33 or later. , If no feature test macros are explicitly defined, then the following feature test macros are defined by default: _BSD_SOURCE (in glibc 2.19 and earlier), _SVID_SOURCE (in glibc 2.19 and earlier), _DEFAULT_SOURCE (since glibc 2.19), _POSIX_SOURCE, and _POSIX_C_SOURCE=200809L (200112L before glibc 2.10; 199506L before glibc 2.4; 199309L before glibc 2.1). If any of __STRICT_ANSI__, _ISOC99_SOURCE, _ISOC11_SOURCE (since glibc 2.18), _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED (in glibc 2.11 and earlier), _BSD_SOURCE (in glibc 2.19 and earlier), or _SVID_SOURCE (in glibc 2.19 and earlier) is explicitly defined, then _BSD_SOURCE, _SVID_SOURCE, and _DEFAULT_SOURCE are not defined by default. _POSIX_SOURCE _POSIX_C_SOURCE __STRICT_ANSI__ _XOPEN_SOURCE 500 , o _POSIX_SOURCE 1; o _POSIX_C_SOURCE : o 2, _XOPEN_SOURCE 500; o 199506L, _XOPEN_SOURCE 500 , 600; o ( glibc 2.4) 200112L, _XOPEN_SOURCE 600 , 700. o ( glibc 2.10) 200809L, _XOPEN_SOURCE 700 . o glibc 200112L 200809L _POSIX_C_SOURCE, glibc. o If _XOPEN_SOURCE is undefined, then the setting of _POSIX_C_SOURCE depends on the glibc version: 199506L, before glibc 2.4; 200112L, since glibc 2.4 to glibc 2.9; and 200809L, since glibc 2.10. ; . POSIX.1 _POSIX_C_SOURCE, _POSIX_SOURCE _XOPEN_SOURCE. _FILE_OFFSET_BITS is not specified by any standard, but is employed on some other implementations. _BSD_SOURCE, _SVID_SOURCE, _DEFAULT_SOURCE, _ATFILE_SOURCE, _GNU_SOURCE, _FORTIFY_SOURCE, _REENTRANT, and _THREAD_SAFE are specific to glibc. _XOPEN_SOURCE_EXTENDED was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later. Linux/glibc. , , , . , , : . , , glibc. , (, __USE_MISC). : . glibc . glibc 2.10 , : $ cc ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 200809L _BSD_SOURCE defined _SVID_SOURCE defined _ATFILE_SOURCE defined $ cc -D_XOPEN_SOURCE=500 ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 199506L _XOPEN_SOURCE defined: 500 $ cc -D_GNU_SOURCE ftm.c $ ./a.out _POSIX_SOURCE defined _POSIX_C_SOURCE defined: 200809L _ISOC99_SOURCE defined _XOPEN_SOURCE defined: 700 _XOPEN_SOURCE_EXTENDED defined _LARGEFILE64_SOURCE defined _BSD_SOURCE defined _SVID_SOURCE defined _ATFILE_SOURCE defined _GNU_SOURCE defined /* ftm.c */ #include #include #include #include int main(int argc, char *argv[]) { #ifdef _POSIX_SOURCE printf("_POSIX_SOURCE defined\n"); #endif #ifdef _POSIX_C_SOURCE printf("_POSIX_C_SOURCE defined: %jdL\n", (intmax_t) _POSIX_C_SOURCE); #endif #ifdef _ISOC99_SOURCE printf("_ISOC99_SOURCE defined\n"); #endif #ifdef _ISOC11_SOURCE printf("_ISOC11_SOURCE defined\n"); #endif #ifdef _XOPEN_SOURCE printf("_XOPEN_SOURCE defined: %d\n", _XOPEN_SOURCE); #endif #ifdef _XOPEN_SOURCE_EXTENDED printf("_XOPEN_SOURCE_EXTENDED defined\n"); #endif #ifdef _LARGEFILE64_SOURCE printf("_LARGEFILE64_SOURCE defined\n"); #endif #ifdef _FILE_OFFSET_BITS printf("_FILE_OFFSET_BITS defined: %d\n", _FILE_OFFSET_BITS); #endif #ifdef _TIME_BITS printf("_TIME_BITS defined: %d\n", _TIME_BITS); #endif #ifdef _BSD_SOURCE printf("_BSD_SOURCE defined\n"); #endif #ifdef _SVID_SOURCE printf("_SVID_SOURCE defined\n"); #endif #ifdef _DEFAULT_SOURCE printf("_DEFAULT_SOURCE defined\n"); #endif #ifdef _ATFILE_SOURCE printf("_ATFILE_SOURCE defined\n"); #endif #ifdef _GNU_SOURCE printf("_GNU_SOURCE defined\n"); #endif #ifdef _REENTRANT printf("_REENTRANT defined\n"); #endif #ifdef _THREAD_SAFE printf("_THREAD_SAFE defined\n"); #endif #ifdef _FORTIFY_SOURCE printf("_FORTIFY_SOURCE defined\n"); #endif exit(EXIT_SUCCESS); } . libc(7), standards(7), system_data_types(7) << >> info libc. /usr/include/features.h Azamat Hackimov , Dmitry Bolkhovskikh , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . feature_test_macros(7)