Manual Pages for Linux CentOS command on man feature_test_macros
MyWebUniversity

Manual Pages for Linux CentOS command on man feature_test_macros

FEATURETESTMACROS(7) Linux Programmer's Manual FEATURETESTMACROS(7)

NAME

featuretestmacros - feature test macros SYNOPSIS

#include DESCRIPTION Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled. NOTE: In order to be effective, a feature test macro must be defined before including any header files. This can be done either in the com‐

pilation command (cc -DMACRO=value) or by defining the macro within the source code before including any headers. Some feature test macros are useful for creating portable applications, by preventing nonstandard definitions from being exposed. Other macros can be used to expose nonstandard definitions that are not exposed by default. The precise effects of each of the feature test macros described below can be ascertained by inspecting the header file. Specification of feature test macro requirements in manual pages When a function requires that a feature test macro is defined, the man‐ ual page SYNOPSIS typically includes a note of the following form (this example from the acct(2) manual page):

#include int acct(const char *filename); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): acct(): BSDSOURCE || (XOPENSOURCE && XOPENSOURCE < 500) The || means that in order to obtain the declaration of acct(2) from , either of the following macro definitions must be made before including any header files:

#define BSDSOURCE

#define XOPENSOURCE /* or any value < 500 */ Alternatively, equivalent definitions can be included in the compila‐ tion command:

cc -DBSDSOURCE

cc -DXOPENSOURCE # Or any value < 500 Note that, as described below, some feature test macros are defined by default, so that it may not always be necessary to explicitly specify the feature test macro(s) shown in the SYNOPSIS. In a few cases, manual pages use a shorthand for expressing the feature test macro requirements (this example from readahead(2)):

#define GNUSOURCE

#include ssizet readahead(int fd, off64t *offset, sizet count); This format is employed in cases where only a single feature test macro can be used to expose the function declaration, and that macro is not defined by default. Feature test macros understood by glibc The following paragraphs explain how feature test macros are handled in Linux glibc 2.x, x > 0. Linux glibc understands the following feature test macros: STRICTANSI ISO Standard C. This macro is implicitly defined by gcc(1) when

invoked with, for example, the -std=c99 or -ansi flag. POSIXCSOURCE Defining this macro causes header files to expose definitions as follows:

· The value 1 exposes definitions conforming to POSIX.1-1990 and ISO C (1990). · The value 2 or greater additionally exposes definitions for

POSIX.2-1992. · The value 199309L or greater additionally exposes definitions

for POSIX.1b (real-time extensions). · The value 199506L or greater additionally exposes definitions for POSIX.1c (threads). · (Since glibc 2.3.3) The value 200112L or greater exposes def‐

initions corresponding to the POSIX.1-2001 base specification (excluding the XSI extension). · (Since glibc 2.10) The value 200809L or greater exposes defi‐

nitions corresponding to the POSIX.1-2008 base specification (excluding the XSI extension). POSIXSOURCE Defining this obsolete macro with any value is equivalent to defining POSIXCSOURCE with the value 1. XOPENSOURCE Defining this macro causes header files to expose definitions as follows: · Defining with any value exposes definitions conforming to POSIX.1, POSIX.2, and XPG4. · The value 500 or greater additionally exposes definitions for SUSv2 (UNIX 98). · (Since glibc 2.2) The value 600 or greater additionally exposes definitions for SUSv3 (UNIX 03; i.e., the

POSIX.1-2001 base specification plus the XSI extension) and C99 definitions. · (Since glibc 2.10) The value 700 or greater additionally

exposes definitions for SUSv4 (i.e., the POSIX.1-2008 base specification plus the XSI extension). XOPENSOURCEEXTENDED If this macro is defined, and XOPENSOURCE is defined, then expose definitions corresponding to the XPG4v2 (SUSv1) UNIX extensions (UNIX 95). This macro is also implicitly defined if XOPENSOURCE is defined with a value of 500 or more. ISOC95SOURCE Exposes ISO C (1990) Amendment 1 definitions (also known as C95). This macro is recognized since glibc 2.12. The primary change in C95 was support for international character sets. The C95 changes were included in the subsequent C99 standard (in other words, ISOC99SOURCE implies ISOC95SOURCE). ISOC99SOURCE Exposes C99 extensions to ISO C (1990). This macro is recog‐ nized since glibc 2.1.3; earlier glibc 2.1.x versions recognized an equivalent macro named ISOC9XSOURCE (because the C99 stan‐ dard had not then been finalized). Although the use of the lat‐ ter macro is obsolete, glibc continues to recognize it for back‐ ward compatibility. ISOC11SOURCE Exposes declarations consistent with the ISO C11 standard. This macro is recognized since glibc 2.16. LARGEFILE64SOURCE Expose definitions for the alternative API specified by the LFS (Large File Summit) as a "transitional extension" to the Single UNIX Specification. (See ⟨http://opengroup.org/platform /lfs.html⟩) The alternative API consists of a set of new objects (i.e., functions and types) whose names are suffixed with "64" (e.g., off64t versus offt, lseek64() versus lseek(), etc.). New programs should not employ this interface; instead FILEOFFSETBITS=64 should be employed. FILEOFFSETBITS Defining this macro with the value 64 automatically converts

references to 32-bit functions and data types related to file

I/O and file system operations into references to their 64-bit counterparts. This is useful for performing I/O on large files

(> 2 Gigabytes) on 32-bit systems. (Defining this macro permits correctly written programs to use large files with only a recom‐

pilation being required.) 64-bit systems naturally permit file sizes greater than 2 Gigabytes, and on those systems this macro has no effect. BSDSOURCE Defining this macro with any value causes header files to expose

BSD-derived definitions. Defining this macro also causes BSD definitions to be preferred in some situations where standards conflict, unless one or more of SVIDSOURCE, POSIXSOURCE, POSIXCSOURCE, XOPENSOURCE, XOPENSOURCEEXTENDED, or GNUSOURCE is defined, in which case BSD definitions are disfa‐ vored. SVIDSOURCE Defining this macro with any value causes header files to expose

System V-derived definitions. (SVID == System V Interface Defi‐ nition; see standards(7).) ATFILESOURCE (since glibc 2.4) Defining this macro with any value causes header files to expose declarations of a range of functions with the suffix "at"; see openat(2). Since glibc 2.10, this macro is also implicitly defined if POSIXCSOURCE is defined with a value greater than or equal to 200809L. GNUSOURCE Defining this macro (with any value) is equivalent to defining BSDSOURCE, SVIDSOURCE, ATFILESOURCE, LARGEFILE64SOURCE, ISOC99SOURCE, XOPENSOURCEEXTENDED, POSIXSOURCE, POSIXCSOURCE with the value 200809L (200112L in glibc ver‐ sions before 2.10; 199506L in glibc versions before 2.5; 199309L in glibc versions before 2.1) and XOPENSOURCE with the value 700 (600 in glibc versions before 2.10; 500 in glibc versions

before 2.2). In addition, various GNU-specific extensions are also exposed. Where standards conflict, BSD definitions are disfavored. REENTRANT Defining this macro exposes definitions of certain reentrant

functions. For multithreaded programs, use cc -pthread instead. THREADSAFE Synonym for REENTRANT, provided for compatibility with some other implementations. FORTIFYSOURCE (since glibc 2.3.4) Defining this macro causes some lightweight checks to be per‐ formed to detect some buffer overflow errors when employing var‐ ious string and memory manipulation functions. Not all buffer overflows are detected, just some common cases. In the current implementation checks are added for calls to memcpy(3), mem‐ pcpy(3), memmove(3), memset(3), stpcpy(3), strcpy(3), strncpy(3), strcat(3), strncat(3), sprintf(3), snprintf(3), vsprintf(3), vsnprintf(3), and gets(3). If FORTIFYSOURCE is

set to 1, with compiler optimization level 1 (gcc -O1) and above, checks that shouldn't change the behavior of conforming programs are performed. With FORTIFYSOURCE set to 2 some more checking is added, but some conforming programs might fail. Some of the checks can be performed at compile time, and result in compiler warnings; other checks take place at run time, and

result in a run-time error if the check fails. Use of this macro requires compiler support, available with gcc(1) since version 4.0. Default definitions, implicit definitions, and combining definitions If no feature test macros are explicitly defined, then the following feature test macros are defined by default: BSDSOURCE, SVIDSOURCE, POSIXSOURCE, and POSIXCSOURCE=200809L (200112L in glibc versions before 2.10; 199506L in glibc versions before 2.4; 199309L in glibc versions before 2.1). If any of STRICTANSI, ISOC99SOURCE, POSIXSOURCE, POSIXCSOURCE, XOPENSOURCE, XOPENSOURCEEXTENDED, BSDSOURCE, or SVIDSOURCE is explicitly defined, then BSDSOURCE, and SVIDSOURCE are not defined by default. If POSIXSOURCE and POSIXCSOURCE are not explicitly defined, and either STRICTANSI is not defined or XOPENSOURCE is defined with a value of 500 or more, then * POSIXSOURCE is defined with the value 1; and * POSIXCSOURCE is defined with one of the following values: · 2, if XOPENSOURCE is defined with a value less than 500; · 199506L, if XOPENSOURCE is defined with a value greater than or equal to 500 and less than 600; or · (since glibc 2.4) 200112L, if XOPENSOURCE is defined with a value greater than or equal to 600 and less than 700. · (Since glibc 2.10) 200809L, if XOPENSOURCE is defined with a value greater than or equal to 700. · Older versions of glibc do not know about the values 200112L and 200809L for POSIXCSOURCE, and the setting of this macro will depend on the glibc version. · If XOPENSOURCE is undefined, then the setting of POSIXCSOURCE depends on the glibc version: 199506L, in glibc versions before 2.4; 200112L, in glibc 2.4 to 2.9; and 200809L, since glibc 2.10. Multiple macros can be defined; the results are additive. CONFORMING TO POSIX.1 specifies POSIXCSOURCE, POSIXSOURCE, and XOPENSOURCE. XOPENSOURCEEXTENDED was specified by XPG4v2 (aka SUSv1). FILEOFFSETBITS is not specified by any standard, but is employed on some other implementations. BSDSOURCE, SVIDSOURCE, ATFILESOURCE, GNUSOURCE, FOR‐ TIFYSOURCE, REENTRANT, and THREADSAFE are specific to Linux (glibc). NOTES

is a Linux/glibc-specific header file. Other systems have an analogous file, but typically with a different name. This header file is automatically included by other header files as required: it is not necessary to explicitly include it in order to employ feature test macros. According to which of the above feature test macros are defined, internally defines various other macros that are checked by other glibc header files. These macros have names prefixed by two underscores (e.g., USEMISC). Programs should never define these macros directly: instead, the appropriate feature test macro(s) from the list above should be employed. EXAMPLE The program below can be used to explore how the various feature test macros are set depending on the glibc version and what feature test macros are explicitly set. The following shell session, on a system with glibc 2.10, shows some examples of what we would see:

$ cc ftm.c

$ ./a.out POSIXSOURCE defined POSIXCSOURCE defined: 200809L BSDSOURCE defined SVIDSOURCE defined ATFILESOURCE defined

$ cc -DXOPENSOURCE=500 ftm.c

$ ./a.out POSIXSOURCE defined POSIXCSOURCE defined: 199506L XOPENSOURCE defined: 500

$ cc -DGNUSOURCE ftm.c

$ ./a.out POSIXSOURCE defined POSIXCSOURCE defined: 200809L ISOC99SOURCE defined XOPENSOURCE defined: 700 XOPENSOURCEEXTENDED defined LARGEFILE64SOURCE defined BSDSOURCE defined SVIDSOURCE defined ATFILESOURCE defined GNUSOURCE defined Program source /* ftm.c */

#include

#include

#include int main(int argc, char *argv[]) {

#ifdef POSIXSOURCE printf("POSIXSOURCE defined\n");

#endif

#ifdef POSIXCSOURCE

printf("POSIXCSOURCE defined: %ldL\n", (long) POSIXCSOURCE);

#endif

#ifdef ISOC99SOURCE printf("ISOC99SOURCE defined\n");

#endif

#ifdef XOPENSOURCE

printf("XOPENSOURCE defined: %d\n", XOPENSOURCE);

#endif

#ifdef XOPENSOURCEEXTENDED printf("XOPENSOURCEEXTENDED defined\n");

#endif

#ifdef LARGEFILE64SOURCE printf("LARGEFILE64SOURCE defined\n");

#endif

#ifdef FILEOFFSETBITS

printf("FILEOFFSETBITS defined: %d\n", FILEOFFSETBITS);

#endif

#ifdef BSDSOURCE printf("BSDSOURCE defined\n");

#endif

#ifdef SVIDSOURCE printf("SVIDSOURCE defined\n");

#endif

#ifdef ATFILESOURCE printf("ATFILESOURCE defined\n");

#endif

#ifdef GNUSOURCE printf("GNUSOURCE defined\n");

#endif

#ifdef REENTRANT printf("REENTRANT defined\n");

#endif

#ifdef THREADSAFE printf("THREADSAFE defined\n");

#endif

#ifdef FORTIFYSOURCE printf("FORTIFYSOURCE defined\n");

#endif exit(EXITSUCCESS); } SEE ALSO libc(7), standards(7) The section "Feature Test Macros" under info libc. /usr/include/features.h COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

Linux 2012-08-05 FEATURETESTMACROS(7)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™