Advanced Programming in the UNIX Environment: Second Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Advanced Programming in the UNIX Environment: Second Edition [Electronic resources] - نسخه متنی

W. Richard Stevens; Stephen A. Rago

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



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.

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

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

  • 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

    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.

  • 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.

  • 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.

  • 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.

  • _PC_CHOWN_RESTRICTED and _PC_NO_TRUNC return 1 without changing errno if the feature is not supported for the specified

    pathname or

    filedes .

  • 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.

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

  • 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.


      / 369