Team BBL
Previous Page Next Page

2.6. Options

We saw the list of POSIX.1 options in Figure 2.5 and discussed XSI option groups in Section 2.2.3. If we are to write portable applications that depend on any of these optionally-supported features, we need a portable way to determine whether an implementation supports a given option.

Just as with limits (Section 2.5), the Single UNIX Specification defines three ways to do this.

  1. Compile-time options are defined in <unistd.h>.

  2. Runtime options that are not associated with a file or a directory are identified with the sysconf function.

  3. Runtime options that are associated with a file or a directory are discovered by calling either the pathconf or the fpathconf function.

The options include the symbols listed in the third column of Figure 2.5, as well as the symbols listed in Figures 2.17 and 2.18. If the symbolic constant is not defined, we must use sysconf, pathconf, or fpathconf to determine whether the option is supported. In this case, the name argument to the function is formed by replacing the _POSIX at the beginning of the symbol with _SC or _PC. For constants that begin with _XOPEN, the name argument is formed by prepending the string with _SC or _PC. For example, if the constant _POSIX_THREADS is undefined, we can call sysconf with the name argument set to _SC_THREADS to determine whether the platform supports the POSIX threads option. If the constant _XOPEN_UNIX is undefined, we can call sysconf with the name argument set to _SC_XOPEN_UNIX to determine whether the platform supports the XSI extensions.

Figure 2.17. Options and name arguments to sysconf

Name of option

Description

name argument

_POSIX_JOB_CONTROL

indicates whether the implementation supports job control

_SC_JOB_CONTROL

_POSIX_READER_WRITER_LOCKS

indicates whether the implementation supports readerwriter locks

_SC_READER_WRITER_LOCKS

_POSIX_SAVED_IDS

indicates whether the implementation supports the saved set-user-ID and the saved set-group-ID

_SC_SAVED_IDS

_POSIX_SHELL

indicates whether the implementation supports the POSIX shell

_SC_SHELL

_POSIX_VERSION

indicates the POSIX.1 version

_SC_VERSION

_XOPEN_CRYPT

indicates whether the implementation supports the XSI encryption option group

_SC_XOPEN_CRYPT

_XOPEN_LEGACY

indicates whether the implementation supports the XSI legacy option group

_SC_XOPEN_LEGACY

_XOPEN_REALTIME

indicates whether the implementation supports the XSI real-time option group

_SC_XOPEN_REALTIME

_XOPEN_REALTIME_THREADS

indicates whether the implementation supports the XSI real-time threads option group

_SC_XOPEN_REALTIME_THREADS

_XOPEN_VERSION

indicates the XSI version

_SC_XOPEN_VERSION


Figure 2.18. Options and name arguments to pathconf and fpathconf

Name of option

Description

name argument

_POSIX_CHOWN_RESTRICTED

indicates whether use of chown is restricted

_PC_CHOWN_RESTRICTED

_POSIX_NO_TRUNC

indicates whether pathnames longer than NAME_MAX generate an error

_PC_NO_TRUNC

_POSIX_VDISABLE

if defined, terminal special characters can be disabled with this value

_PC_VDISABLE

_POSIX_ASYNC_IO

indicates whether asynchronous I/O can be used with the associated file

_PC_ASYNC_IO

_POSIX_PRIO_IO

indicates whether prioritized I/O can be used with the associated file

_PC_PRIO_IO

_POSIX_SYNC_IO

indicates whether synchronized I/O can be used with the associated file

_PC_SYNC_IO


If the symbolic constant is defined by the platform, we have three possibilities.

  1. If the symbolic constant is defined to have the value 1, then the corresponding option is unsupported by the platform.

  2. If the symbolic constant is defined to be greater than zero, then the corresponding option is supported.

  3. If the symbolic constant is defined to be equal to zero, then we must call sysconf, pathconf, or fpathconf to determine whether the option is supported.

Figure 2.17 summarizes the options and their symbolic constants that can be used with sysconf, in addition to those listed in Figure 2.5.

The symbolic constants used with pathconf and fpathconf are summarized in Figure 2.18. As with the system limits, there are several points to note regarding how options are treated by sysconf, pathconf, and fpathconf.

  1. The value returned for _SC_VERSION indicates the four-digit year and two-digit month of the standard. This value can be 198808L, 199009L, 199506L, or some other value for a later version of the standard. The value associated with Version 3 of the Single UNIX Specification is 200112L.

  2. The value returned for _SC_XOPEN_VERSION indicates the version of the XSI that the system complies with. The value associated with Version 3 of the Single UNIX Specification is 600.

  3. The values _SC_JOB_CONTROL, _SC_SAVED_IDS, and _PC_VDISABLE no longer represent optional features. As of Version 3 of the Single UNIX Specification, these features are now required, although these symbols are retained for backward compatibility.

  4. _PC_CHOWN_RESTRICTED and _PC_NO_TRUNC return 1 without changing errno if the feature is not supported for the specified pathname or filedes.

  5. The referenced file for _PC_CHOWN_RESTRICTED must be either a file or a directory. If it is a directory, the return value indicates whether this option applies to files within that directory.

  6. The referenced file for _PC_NO_TRUNC must be a directory. The return value applies to filenames within the directory.

  7. The referenced file for _PC_VDISABLE must be a terminal file.

In Figure 2.19 we show several configuration options and their corresponding values on the four sample systems we discuss in this text. Note that several of the systems haven't yet caught up to the latest version of the Single UNIX Specification. For example, Mac OS X 10.3 supports POSIX threads but defines _POSIX_THREADS as

   #define _POSIX_THREADS

without specifying a value. To conform to Version 3 of the Single UNIX Specification, the symbol, if defined, should be set to -1, 0, or 200112.

Figure 2.19. Examples of configuration options

Limit

FreeBSD 5.2.1

Linux 2.4.22

Mac OS X 10.3

Solaris 9

UFS file system

PCFS file system

_POSIX_CHOWN_RESTRICTED

1

1

1

1

1

_POSIX_JOB_CONTROL

1

1

1

1

1

_POSIX_NO_TRUNC

1

1

1

1

unsupported

_POSIX_SAVED_IDS

unsupported

1

unsupported

1

1

_POSIX_THREADS

200112

200112

defined

1

1

_POSIX_VDISABLE

255

0

255

0

0

_POSIX_VERSION

200112

200112

198808

199506

199506

_XOPEN_UNIX

unsupported

1

undefined

1

1

_XOPEN_VERSION

unsupported

500

undefined

3

3


An entry is marked as "undefined" if the feature is not defined, i.e., the system doesn't define the symbolic constant or its corresponding _PC or _SC name. In contrast, the "defined" entry means that the symbolic constant is defined, but no value is specified, as in the preceding _POSIX_THREADS example. An entry is "unsupported" if the system defines the symbolic constant, but it has a value of -1, or it has a value of 0 but the corresponding sysconf or pathconf call returned -1.

Note that pathconf returns a value of 1 for _PC_NO_TRUNC when 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 are silently truncated to the 8.3 format limit that the DOS file system requires.

    Team BBL
    Previous Page Next Page