unistd.h - standard symbolic constants and types
#include <unistd.h>
The <unistd.h> header defines miscellaneous symbolic constants and types, and declares miscellaneous functions. The actual values of the constants are unspecified except as shown. The contents of this header are shown below.
The following symbolic constants shall be defined:
The following symbolic constant shall be defined only if the implementation supports the XSI option; see XSI Conformance .
Integer value indicating version of the X/Open Portability Guide to which the implementation conforms. The value shall be 600. <img src="../images/opt-end.gif" alt="[Option End]" border="0">
The following symbolic constants, if defined in <unistd.h>, shall have a value of -1, 0, or greater, unless otherwise specified below. If these are undefined, the fpathconf(), pathconf(), or sysconf() functions can be used to determine whether the option is provided for a particular invocation of the application.
If a symbolic constant is defined with the value -1, the option is not supported. Headers, data types, and function interfaces required only for the option need not be supplied. An application that attempts to use anything associated only with the option is considered to be requiring an extension.
If a symbolic constant is defined with a value greater than zero, the option shall always be supported when the application is executed. All headers, data types, and functions shall be present and shall operate as specified.
If a symbolic constant is defined with the value zero, all headers, data types, and functions shall be present. The application can check at runtime to see whether the option is supported by calling fpathconf(), pathconf(), or sysconf() with the indicated name parameter.
Unless explicitly specified otherwise, the behavior of functions associated with an unsupported option is unspecified, and an application that uses such functions without first checking fpathconf(), pathconf(), or sysconf() is considered to be requiring an extension.
For conformance requirements, refer to Conformance .
The implementation supports the Advisory Information option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Asynchronous Input and Output option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Barriers option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Clock Selection option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Process CPU-Time Clocks option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the File Synchronization option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Memory Mapped Files option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Process Memory Locking option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Range Memory Locking option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Memory Protection option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Message Passing option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Monotonic Clock option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Prioritized Input and Output option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Process Scheduling option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Raw Sockets option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Read-Write Locks option. This is always set to a value greater than zero if the Threads option is supported. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Realtime Signals Extension option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Semaphores option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Shared Memory Objects option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Spawn option. If this symbol has a value other than -1 or 0, it shall have the value 200112L. <img src="../images/opt-end.gif" alt="[Option End]" border="0">
The implementation supports the Spin Locks option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Process Sporadic Server option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Synchronized Input and Output option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Stack Address Attribute option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Stack Size Attribute option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread CPU-Time Clocks option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Priority Inheritance option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Priority Protection option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Execution Scheduling option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Process-Shared Synchronization option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread-Safe Functions option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Thread Sporadic Server option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Threads option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Timeouts option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Timers option. If this symbol has a value other than -1 or 0, it shall have the value 200112L. <img src="../images/opt-end.gif" alt="[Option End]" border="0">
The implementation supports the Trace option. If this symbol has a value other than -1 or 0, it shall have the value 200112L. <img src="../images/opt-end.gif" alt="[Option End]" border="0">
The implementation supports the Trace Event Filter option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Trace Inherit option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Trace Log option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Typed Memory Objects option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the C-Language Development Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the FORTRAN Development Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the FORTRAN Runtime Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Batch Environment Services and Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Batch Accounting option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Batch Checkpoint/Restart option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Locate Batch Job Request option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Batch Job Message Request option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Track Batch Job Request option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the Software Development Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation supports the User Portability Utilities option. If this symbol has a value other than -1 or 0, it shall have the value 200112L.
The implementation provides a C-language compilation environment with 32-bit int, long, pointer, and off_t types.
The implementation provides a C-language compilation environment with 32-bit int, long, and pointer types and an off_t type using at least 64 bits.
The implementation provides a C-language compilation environment with 32-bit int and 64-bit long, pointer, and off_t types.
The implementation provides a C-language compilation environment with an int type using at least 32 bits and long, pointer, and off_t types using at least 64 bits.
The implementation supports the X/Open Encryption Option Group.
The implementation supports the XSI extension.
If any of the following constants are not defined in the <unistd.h> header, the value shall vary depending on the file to which it is applied.
If any of the following constants are defined to have value -1 in the <unistd.h> header, the implementation shall not provide the option on any file; if any are defined to have a value other than -1 in the <unistd.h> header, the implementation shall provide the option on all applicable files.
All of the following constants, whether defined in <unistd.h> or not, may be queried with respect to a specific file using the pathconf() or fpathconf() functions:
The following symbolic constant shall be defined:
The following symbolic constants shall be defined for the access() function:
The constants F_OK, R_OK, W_OK, and X_OK and the expressions R_OK|W_OK, R_OK|X_OK, and R_OK|W_OK|X_OK shall all have distinct values.
The following symbolic constants shall be defined for the confstr() function:
The following symbolic constants are reserved for compatibility with Issue 5:
_CS_XBS5_ILP32_OFF32_CFLAGS (LEGACY)
_CS_XBS5_ILP32_OFF32_LDFLAGS (LEGACY)
_CS_XBS5_ILP32_OFF32_LIBS (LEGACY)
_CS_XBS5_ILP32_OFF32_LINTFLAGS (LEGACY)
_CS_XBS5_ILP32_OFFBIG_CFLAGS (LEGACY)
_CS_XBS5_ILP32_OFFBIG_LDFLAGS (LEGACY)
_CS_XBS5_ILP32_OFFBIG_LIBS (LEGACY)
_CS_XBS5_ILP32_OFFBIG_LINTFLAGS (LEGACY)
_CS_XBS5_LP64_OFF64_CFLAGS (LEGACY)
_CS_XBS5_LP64_OFF64_LDFLAGS (LEGACY)
_CS_XBS5_LP64_OFF64_LIBS (LEGACY)
_CS_XBS5_LP64_OFF64_LINTFLAGS (LEGACY)
_CS_XBS5_LPBIG_OFFBIG_CFLAGS (LEGACY)
_CS_XBS5_LPBIG_OFFBIG_LDFLAGS (LEGACY)
_CS_XBS5_LPBIG_OFFBIG_LIBS (LEGACY)
_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS (LEGACY)
The following symbolic constants shall be defined for the lseek() and fcntl() functions and shall have distinct values:
The following symbolic constants shall be defined as possible values for the function argument to the lockf() function:
The following symbolic constants shall be defined for pathconf():
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
_PC_CHOWN_RESTRICTED
_PC_FILESIZEBITS
_PC_LINK_MAX
_PC_MAX_CANON
_PC_MAX_INPUT
_PC_NAME_MAX
_PC_NO_TRUNC
_PC_PATH_MAX
_PC_PIPE_BUF
_PC_PRIO_IO
_PC_REC_INCR_XFER_SIZE
_PC_REC_MIN_XFER_SIZE
_PC_REC_XFER_ALIGN
_PC_SYMLINK_MAX
_PC_SYNC_IO
_PC_VDISABLE
The following symbolic constants shall be defined for sysconf():
_SC_2_C_BIND
_SC_2_C_DEV
_SC_2_C_VERSION
_SC_2_CHAR_TERM
_SC_2_FORT_DEV
_SC_2_FORT_RUN
_SC_2_LOCALEDEF
_SC_2_PBS
_SC_2_PBS_ACCOUNTING
_SC_2_PBS_CHECKPOINT
_SC_2_PBS_LOCATE
_SC_2_PBS_MESSAGE
_SC_2_PBS_TRACK
_SC_2_SW_DEV
_SC_2_UPE
_SC_2_VERSION
_SC_ADVISORY_INFO
_SC_ARG_MAX
_SC_AIO_LISTIO_MAX
_SC_AIO_MAX
_SC_AIO_PRIO_DELTA_MAX
_SC_ASYNCHRONOUS_IO
_SC_ATEXIT_MAX
_SC_BARRIERS
_SC_BC_BASE_MAX
_SC_BC_DIM_MAX
_SC_BC_SCALE_MAX
_SC_BC_STRING_MAX
_SC_CHILD_MAX
_SC_CLK_TCK
_SC_CLOCK_SELECTION
_SC_COLL_WEIGHTS_MAX
_SC_CPUTIME
_SC_DELAYTIMER_MAX
_SC_EXPR_NEST_MAX
_SC_FILE_LOCKING
_SC_FSYNC
_SC_GETGR_R_SIZE_MAX
_SC_GETPW_R_SIZE_MAX
_SC_HOST_NAME_MAX
_SC_IOV_MAX
_SC_IPV6
_SC_JOB_CONTROL
_SC_LINE_MAX
_SC_LOGIN_NAME_MAX
_SC_MAPPED_FILES
_SC_MEMLOCK
_SC_MEMLOCK_RANGE
_SC_MEMORY_PROTECTION
_SC_MESSAGE_PASSING
_SC_MONOTONIC_CLOCK
_SC_MQ_OPEN_MAX
_SC_MQ_PRIO_MAX
_SC_NGROUPS_MAX
_SC_OPEN_MAX
_SC_PAGE_SIZE
_SC_PAGESIZE
_SC_PRIORITIZED_IO
_SC_PRIORITY_SCHEDULING
_SC_RAW_SOCKETS
_SC_RE_DUP_MAX
_SC_READER_WRITER_LOCKS
_SC_REALTIME_SIGNALS
_SC_REGEXP
_SC_RTSIG_MAX
_SC_SAVED_IDS
_SC_SEMAPHORES
_SC_SEM_NSEMS_MAX
_SC_SEM_VALUE_MAX
_SC_SHARED_MEMORY_OBJECTS
_SC_SHELL
_SC_SIGQUEUE_MAX
_SC_SPAWN
_SC_SPIN_LOCKS
_SC_SPORADIC_SERVER
_SC_STREAM_MAX
_SC_SYMLOOP_MAX
_SC_SYNCHRONIZED_IO
_SC_THREAD_ATTR_STACKADDR
_SC_THREAD_ATTR_STACKSIZE
_SC_THREAD_CPUTIME
_SC_THREAD_DESTRUCTOR_ITERATIONS
_SC_THREAD_KEYS_MAX
_SC_THREAD_PRIO_INHERIT
_SC_THREAD_PRIO_PROTECT
_SC_THREAD_PRIORITY_SCHEDULING
_SC_THREAD_PROCESS_SHARED
_SC_THREAD_SAFE_FUNCTIONS
_SC_THREAD_SPORADIC_SERVER
_SC_THREAD_STACK_MIN
_SC_THREAD_THREADS_MAX
_SC_TIMEOUTS
_SC_THREADS
_SC_TIMER_MAX
_SC_TIMERS
_SC_TRACE
_SC_TRACE_EVENT_FILTER
_SC_TRACE_INHERIT
_SC_TRACE_LOG
_SC_TTY_NAME_MAX
_SC_TYPED_MEMORY_OBJECTS
_SC_TZNAME_MAX
_SC_V6_ILP32_OFF32
_SC_V6_ILP32_OFFBIG
_SC_V6_LP64_OFF64
_SC_V6_LPBIG_OFFBIG
_SC_VERSION
_SC_XBS5_ILP32_OFF32 (LEGACY)
_SC_XBS5_ILP32_OFFBIG (LEGACY)
_SC_XBS5_LP64_OFF64 (LEGACY)
_SC_XBS5_LPBIG_OFFBIG (LEGACY)
_SC_XOPEN_CRYPT
_SC_XOPEN_ENH_I18N
_SC_XOPEN_LEGACY
_SC_XOPEN_REALTIME
_SC_XOPEN_REALTIME_THREADS
_SC_XOPEN_SHM
_SC_XOPEN_STREAMS
_SC_XOPEN_UNIX
_SC_XOPEN_VERSION
_SC_XOPEN_XCU_VERSION
The two constants _SC_PAGESIZE and _SC_PAGE_SIZE may be defined to have the same value.
The following symbolic constants shall be defined for file streams:
The size_t, ssize_t, uid_t, gid_t, off_t, pid_t, and useconds_t types shall be defined as described in <sys/types.h>.
The intptr_t type shall be defined as described in <inttypes.h>.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
int access(const char *, int); unsigned alarm(unsigned); int chdir(const char *); int chown(const char *, uid_t, gid_t); int close(int); size_t confstr(int, char *, size_t); char *crypt(const char *, const char *); char *ctermid(char *); int dup(int); int dup2(int, int); void encrypt(char[64], int); int execl(const char *, const char *, ...); int execle(const char *, const char *, ...); int execlp(const char *, const char *, ...); int execv(const char *, char *const []); int execve(const char *, char *const [], char *const []); int execvp(const char *, char *const []); void _exit(int); int fchown(int, uid_t, gid_t); int fchdir(int); int fdatasync(int); pid_t fork(void); long fpathconf(int, int); int fsync(int); int ftruncate(int, off_t); char *getcwd(char *, size_t); gid_t getegid(void); uid_t geteuid(void); gid_t getgid(void); int getgroups(int, gid_t []); long gethostid(void); int gethostname(char *, size_t); char *getlogin(void); int getlogin_r(char *, size_t); int getopt(int, char * const [], const char *); pid_t getpgid(pid_t); pid_t getpgrp(void); pid_t getpid(void); pid_t getppid(void); pid_t getsid(pid_t); uid_t getuid(void); char *getwd(char *); (LEGACY ) int isatty(int); int lchown(const char *, uid_t, gid_t); int link(const char *, const char *); int lockf(int, int, off_t); off_t lseek(int, off_t, int); int nice(int); long pathconf(const char *, int); int pause(void); int pipe(int [2]); ssize_t pread(int, void *, size_t, off_t); ssize_t pwrite(int, const void *, size_t, off_t); ssize_t read(int, void *, size_t); ssize_t readlink(const char *restrict, char *restrict, size_t); int rmdir(const char *); int setegid(gid_t); int seteuid(uid_t); int setgid(gid_t); int setpgid(pid_t, pid_t); pid_t setpgrp(void); int setregid(gid_t, gid_t); int setreuid(uid_t, uid_t); pid_t setsid(void); int setuid(uid_t); unsigned sleep(unsigned); void swab(const void *restrict, void *restrict, ssize_t); int symlink(const char *, const char *); void sync(void); long sysconf(int); pid_t tcgetpgrp(int); int tcsetpgrp(int, pid_t); int truncate(const char *, off_t); char *ttyname(int); int ttyname_r(int, char *, size_t); useconds_t ualarm(useconds_t, useconds_t); int unlink(const char *); int usleep(useconds_t); pid_t vfork(void); ssize_t write(int, const void *, size_t);
Implementations may also include the pthread_atfork() prototype as defined in <pthread.h> .
The following external variables shall be declared:
extern char *optarg; extern int optind, opterr, optopt;
The following sections are informative.
IEEE Std 1003.1-2001 only describes the behavior of systems that claim conformance to it. However, application developers who want to write applications that adapt to other versions of IEEE Std 1003.1 (or to systems that do not conform to any POSIX standard) may find it useful to code them so as to conditionally compile different code depending on the value of _POSIX_VERSION, for example:
#if _POSIX_VERSION >= 200112L /* Use the newer function that copes with large files. */ off_t pos=ftello(fp); #else /* Either this is an old version of POSIX, or _POSIX_VERSION is not even defined, so use the traditional function. */ long pos=ftell(fp); #endif
Earlier versions of IEEE Std 1003.1 and of the Single UNIX Specification can be identified by the following macros:
IEEE Std 1003.1-2001 does not make any attempt to define application binary interaction with the underlying operating system. However, application developers may find it useful to query _SC_VERSION at runtime via sysconf() to determine whether the current version of the operating system supports the necessary functionality as in the following program fragment:
if (sysconf(_SC_VERSION) < 200112L) { fprintf(stderr, "POSIX.1-2001 system required, terminating \n"); exit(1); }
New applications should not use _XOPEN_SHM or _XOPEN_ENH_I18N.
As IEEE Std 1003.1-2001 evolved, certain options became sufficiently standardized that it was concluded that simply requiring one of the option choices was simpler than retaining the option. However, for backwards-compatibility, the option flags (with required constant values) are retained.
The standard developers considered altering the definition of _POSIX_VERSION and removing _SC_VERSION from the specification of sysconf() since the utility to an application was deemed by some to be minimal, and since the implementation of the functionality is potentially problematic. However, they recognized that support for existing application binaries is a concern to manufacturers, application developers, and the users of implementations conforming to IEEE Std 1003.1-2001.
While the example using _SC_VERSION in the APPLICATION USAGE section does not provide the greatest degree of imaginable utility to the application developer or user, it is arguably better than a core file or some other equally obscure result. (It is also possible for implementations to encode and recognize application binaries compiled in various POSIX.1-conforming environments, and modify the semantics of the underlying system to conform to the expectations of the application.) For the reasons outlined in the preceding paragraphs and in the APPLICATION USAGE section, the standard developers elected to retain the _POSIX_VERSION and _SC_VERSION functionality.
IEEE Std 1003.1-2001 now includes support in certain areas for the newly adopted policy governing options and stubs.
This policy provides flexibility for implementations in how they support options. It also specifies how conforming applications can adapt to different implementations that support different sets of options. It allows the following:
If an implementation has no interest in supporting an option, it does not have to provide anything associated with that option beyond the announcement that it does not support it.
An implementation can support a partial or incompatible version of an option (as a non-standard extension) as long as it does not claim to support the option.
An application can determine whether the option is supported. A strictly conforming application must check this announcement mechanism before first using anything associated with the option.
There is an important implication of this policy. IEEE Std 1003.1-2001 cannot dictate the behavior of interfaces associated with an option when the implementation does not claim to support the option. In particular, it cannot require that a function associated with an unsupported option will fail if it does not perform as specified. However, this policy does not prevent a standard from requiring certain functions to always be present, but that they shall always fail on some implementations. The setpgid() function in the POSIX.1-1990 standard, for example, is considered appropriate.
The POSIX standards include various options, and the C-language binding support for an option implies that the implementation must supply data types and function interfaces. An application must be able to discover whether the implementation supports each option.
Any application must consider the following three cases for each option:
Option never supported.
The implementation advertises at compile time that the option will never be supported. In this case, it is not necessary for the implementation to supply any of the data types or function interfaces that are provided only as part of the option. The implementation might provide data types and functions that are similar to those defined by IEEE Std 1003.1-2001, but there is no guarantee for any particular behavior.
Option always supported.
The implementation advertises at compile time that the option will always be supported. In this case, all data types and function interfaces shall be available and shall operate as specified.
Option might or might not be supported.
Some implementations might not provide a mechanism to specify support of options at compile time. In addition, the implementation might be unable or unwilling to specify support or non-support at compile time. In either case, any application that might use the option at runtime must be able to compile and execute. The implementation must provide, at compile time, all data types and function interfaces that are necessary to allow this. In this situation, there must be a mechanism that allows the application to query, at runtime, whether the option is supported. If the application attempts to use the option when it is not supported, the result is unspecified unless explicitly specified otherwise in IEEE Std 1003.1-2001.
<inttypes.h> , <limits.h> , <sys/socket.h> , <sys/types.h> , <termios.h> , <wctype.h> , the System Interfaces volume of IEEE Std 1003.1-2001, access(), alarm(), chdir(), chown(), close(), crypt(), ctermid(), dup(), encrypt(), environ, exec, exit(), fchdir(), fchown(), fcntl(), fork(), fpathconf(), fsync(), ftruncate(), getcwd(), getegid(), geteuid(), getgid(), getgroups(), gethostid(), gethostname(), getlogin(), getpgid(), getpgrp(), getpid(), getppid(), getsid(), getuid(), isatty(), lchown(), link(), lockf(), lseek(), nice(), pathconf(), pause(), pipe(), read(), readlink(), rmdir(), setgid(), setpgid(), setpgrp(), setregid(), setreuid(), setsid(), setuid(), sleep(), swab(), symlink(), sync(), sysconf(), tcgetpgrp(), tcsetpgrp(), truncate(), ttyname(), ualarm(), unlink(), usleep(), vfork(), write()
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |