Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 2.7 FeatureTest Macros 57


Figure2.20 shows several configuration options and their corresponding values on
the four sample systems we discuss in this text. An entry is ‘‘unsupported’’ if the
system defines the symbolic constant but it has a value of−1, or if it has a value of 0 but
the correspondingsysconforpathconfcall returned−1. It is interesting to see that
some system implementations haven’t yet caught up to the latest version of the Single
UNIX Specification.

Solaris 10
FreeBSD Linux Mac OS X
UFS PCFS
8.0 3.2.0 10.6.8 file system file system

Limit

_POSIX_CHOWN_RESTRICTED 11200112 1 1
_POSIX_JOB_CONTROL 11200112 1 1
_POSIX_NO_TRUNC 11200112 1 unsupported
_POSIX_SAVED_IDS unsupported 1 200112 1 1
_POSIX_THREADS 200112 200809 200112 200112 200112
_POSIX_VDISABLE 255 0 255 0 0
_POSIX_VERSION 200112 200809 200112 200112 200112
_XOPEN_UNIX unsupported 1 1 1 1
_XOPEN_VERSION unsupported 700 600 600 600

Figure 2.20Examples of configuration options

Note thatpathconfreturns a value of−1for_PC_NO_TRUNCwhen used with a
file from a PCFS file system on Solaris. The PCFS file system supports the DOS format
(for floppy disks), and DOS filenames aresilently truncated to the 8.3 format limit that
the DOS file system requires.

2.7 Feature Test Macros


The headers define numerous POSIX.1 and XSI symbols, as we’ve described. Even so,
most implementations can add their own definitions to these headers, in addition to the
POSIX.1 and XSI definitions. If we want to compile a program so that it depends only
on the POSIX definitions and doesn’t conflict with any implementation-defined
constants, we need to define the constant_POSIX_C_SOURCE.All the POSIX.1 headers
use this constant to exclude any implementation-defined definitions when
_POSIX_C_SOURCEis defined.

Older versions of the POSIX.1 standarddefined the_POSIX_SOURCEconstant. This was
superseded by the_POSIX_C_SOURCEconstant in the 2001 version of POSIX.1.

The constants _POSIX_C_SOURCEand _XOPEN_SOURCE arecalled featuretest
macros.All featuretest macros begin with an underscore. When used, they aretypically
defined in thecccommand, as in
cc -D_POSIX_C_SOURCE=200809L file.c
Free download pdf