unistd.h(7POSIX)
๐ unistd.h(7POSIX) โ POSIX Programmer's Manual ๐
hey bestie, welcome to the <unistd.h> glow-up. this is page 7POSIX of the POSIX Programmer's Manual, and it's a long one, so we're doing it in five parts. part one starts right here. let's gooo โจ
๐ PROLOG ๐
okay so first thing: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ โ so if you're on Linux, pls go consult the corresponding Linux manual page for the deets on Linux behavior. or, plot twist, the interface might not even be implemented on Linux at all. ๐
โจ NAME โจ
unistd.h โ standard symbolic constants and types. that's it, that's the name, it's giving iconic header file energy ๐
๐ฆ SYNOPSIS ๐ฆ
#include <unistd.h>
just that one line, no cap. so simple, so clean ๐ซถ
๐ DESCRIPTION ๐
the <unistd.h> header defines miscellaneous symbolic constants and types, and it declares miscellaneous functions too. basically it's the header that has a little bit of everything.
the actual values of the constants are unspecified except as shown. and the contents of this header? they're shown below, bestie. keep reading. โฌ๏ธ
๐ธ Version Test Macros ๐ธ
the <unistd.h> header shall define the following symbolic constants. their values shall be suitable for use in #if preprocessing directives (yes, the preprocessor ones, we love a compile-time moment).
_POSIX_VERSIONโ an integer value indicating the version of this standard (the C-language binding) that the implementation conforms to. for implementations conforming to POSIX.1-2008, the value shall be200809L. โญ_POSIX2_VERSIONโ an integer value indicating the version of the Shell and Utilities volume of POSIX.1 that the implementation conforms to. for implementations conforming to POSIX.1-2008, the value shall be200809L. now here's the โจ nuance โจ โ for profile implementations that define_POSIX_SUBPROFILE(see Section 2.1.5.1, Subprofiling Considerations) in<unistd.h>,_POSIX2_VERSIONmay be left undefined, or be defined with the value-1, to indicate that the Shell and Utilities volume of POSIX.1 is not supported. in that case, a call tosysconf(_SC_2_VERSION)shall return either200809Lor-1, indicating that the Shell and Utilities volume of POSIX.1 is, or is not, respectively, supported at runtime. lowkey a whole saga, but we move. ๐
the <unistd.h> header shall define the following symbolic constant only if the implementation supports the XSI option โ see Section 2.1.4, XSI Conformance. if defined, its value shall be suitable for use in #if preprocessing directives.
_XOPEN_VERSIONโ an integer value indicating the version of the X/Open Portability Guide that the implementation conforms to. the value shall be700. ๐
๐ Constants for Options and Option Groups ๐
the following symbolic constants, if defined in <unistd.h>, shall have a value of -1, 0, or greater โ unless otherwise specified below. (and for profile implementations that define _POSIX_SUBPROFILE (see Section 2.1.5.1, Subprofiling Considerations) in <unistd.h>, the constants described below as always having a value greater than zero don't have to be defined, and if they are defined they may have a value of -1, 0, or greater.) the values shall be suitable for use in #if preprocessing directives.
so like, here's the vibe check on what those numbers mean:
- if a symbolic constant is not defined or is defined with the value
-1, the option is not supported for compilation. - if it's defined with a value greater than zero, the option shall always be supported when the application is executed.
- if it's defined with the value zero, the option shall be supported for compilation and might or might not be supported at runtime. it's giving mystery, it's giving "we'll see" ๐ญ
see Section 2.1.6, Options for further information about the conformance requirements of these three categories of support.
alright, the list. it's long. hydrate first. ๐ง
_POSIX_ADVISORY_INFOโ the implementation supports the Advisory Information option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_ASYNCHRONOUS_IOโ the implementation supports asynchronous input and output. this symbol shall always be set to the value200809L._POSIX_BARRIERSโ the implementation supports barriers. this symbol shall always be set to the value200809L._POSIX_CHOWN_RESTRICTEDโ the use ofchown()andfchown()is restricted to a process with appropriate privileges, and to changing the group ID of a file only to the effective group ID of the process or to one of its supplementary group IDs. this symbol shall be defined with a value other than-1. ๐_POSIX_CLOCK_SELECTIONโ the implementation supports clock selection. this symbol shall always be set to the value200809L._POSIX_CPUTIMEโ the implementation supports the Process CPU-Time Clocks option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_FSYNCโ the implementation supports the File Synchronization option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_IPV6โ the implementation supports the IPv6 option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_JOB_CONTROLโ the implementation supports job control. this symbol shall always be set to a value greater than zero._POSIX_MAPPED_FILESโ the implementation supports memory mapped Files. this symbol shall always be set to the value200809L._POSIX_MEMLOCKโ the implementation supports the Process Memory Locking option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_MEMLOCK_RANGEโ the implementation supports the Range Memory Locking option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_MEMORY_PROTECTIONโ the implementation supports memory protection. this symbol shall always be set to the value200809L._POSIX_MESSAGE_PASSINGโ the implementation supports the Message Passing option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_MONOTONIC_CLOCKโ the implementation supports the Monotonic Clock option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_NO_TRUNCโ pathname components longer than{NAME_MAX}generate an error. this symbol shall be defined with a value other than-1. โ ๏ธ_POSIX_PRIORITIZED_IOโ the implementation supports the Prioritized Input and Output option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_PRIORITY_SCHEDULINGโ the implementation supports the Process Scheduling option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_RAW_SOCKETSโ the implementation supports the Raw Sockets option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_READER_WRITER_LOCKSโ the implementation supports read-write locks. this symbol shall always be set to the value200809L._POSIX_REALTIME_SIGNALSโ the implementation supports realtime signals. this symbol shall always be set to the value200809L._POSIX_REGEXPโ the implementation supports the Regular Expression Handling option. this symbol shall always be set to a value greater than zero._POSIX_SAVED_IDSโ each process has a saved set-user-ID and a saved set-group-ID. this symbol shall always be set to a value greater than zero._POSIX_SEMAPHORESโ the implementation supports semaphores. this symbol shall always be set to the value200809L._POSIX_SHARED_MEMORY_OBJECTSโ the implementation supports the Shared Memory Objects option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_SHELLโ the implementation supports the POSIX shell. this symbol shall always be set to a value greater than zero._POSIX_SPAWNโ the implementation supports the Spawn option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_SPIN_LOCKSโ the implementation supports spin locks. this symbol shall always be set to the value200809L._POSIX_SPORADIC_SERVERโ the implementation supports the Process Sporadic Server option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_SYNCHRONIZED_IOโ the implementation supports the Synchronized Input and Output option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_THREAD_ATTR_STACKADDRโ the implementation supports the Thread Stack Address Attribute option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_THREAD_ATTR_STACKSIZEโ the implementation supports the Thread Stack Size Attribute option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_THREAD_CPUTIMEโ the implementation supports the Thread CPU-Time Clocks option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L._POSIX_THREAD_PRIO_INHERITโ the implementation supports the Non-Robust Mutex Priority Inheritance option. if this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. the value of this symbol reported bysysconf()shall either be-1or200809L.
and that's a wrap on part one, bestie โ but we are SO not done. more of this header is coming, so don't go anywhere ๐ซถโจ
_POSIX_THREAD_PRIO_PROTECTโ bestie, this one means the implementation supports the Non-Robust Mutex Priority Protection option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. And the value thatsysconf()reports for it shall either be-1or200809L. That's it, that's the whole vibe. ๐_POSIX_THREAD_PRIORITY_SCHEDULINGโ supports the Thread Execution Scheduling option. If it's defined in<unistd.h>, it shall be-1,0, or200809L. Thesysconf()value shall be either-1or200809L. ๐_POSIX_THREAD_PROCESS_SHAREDโ supports the Thread Process-Shared Synchronization option. Defined in<unistd.h>? Then it shall be-1,0, or200809L.sysconf()reports either-1or200809L. slay. โจ_POSIX_THREAD_ROBUST_PRIO_INHERITโ supports the Robust Mutex Priority Inheritance option. If defined in<unistd.h>, it shall be defined to be-1,0, or200809L. Thesysconf()value shall either be-1or200809L. ๐ซถ_POSIX_THREAD_ROBUST_PRIO_PROTECTโ supports the Robust Mutex Priority Protection option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. iconic behavior fr fr. ๐_POSIX_THREAD_SAFE_FUNCTIONSโ the implementation supports thread-safe functions. And listen, this one isn't a maybe: this symbol shall always be set to the value200809L. No negotiating. periodt. ๐_POSIX_THREAD_SPORADIC_SERVERโ supports the Thread Sporadic Server option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value reported bysysconf()shall either be-1or200809L. ๐ฆ_POSIX_THREADSโ the implementation supports threads. This symbol shall always be set to the value200809L. always always. ๐ฅ_POSIX_TIMEOUTSโ the implementation supports timeouts. This symbol shall always be set to the value200809L. ๐ซ_POSIX_TIMERSโ the implementation supports timers. This symbol shall always be set to the value200809L. โฐโจ_POSIX_TRACEโ supports the Trace option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. Thesysconf()value shall either be-1or200809L. ๐_POSIX_TRACE_EVENT_FILTERโ supports the Trace Event Filter option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐_POSIX_TRACE_INHERITโ supports the Trace Inherit option. If defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value reported bysysconf()shall either be-1or200809L. ๐ธ_POSIX_TRACE_LOGโ supports the Trace Log option. If this symbol is defined in<unistd.h>, it shall be-1,0, or200809L.sysconf()shall report either-1or200809L. ๐_POSIX_TYPED_MEMORY_OBJECTSโ supports the Typed Memory Objects option. If defined in<unistd.h>, it shall be defined to be-1,0, or200809L. And the value reported bysysconf()shall either be-1or200809L. ๐ง_POSIX_V6_ILP32_OFF32โ the implementation provides a C-language compilation environment with 32-bitint,long, pointer, andoff_ttypes. ๐_POSIX_V6_ILP32_OFFBIGโ the implementation provides a C-language compilation environment with 32-bitint,long, and pointer types, and anoff_ttype using at least 64 bits. ๐ฆ_POSIX_V6_LP64_OFF64โ the implementation provides a C-language compilation environment with 32-bitintand 64-bitlong, pointer, andoff_ttypes. โจ_POSIX_V6_LPBIG_OFFBIGโ the implementation provides a C-language compilation environment with aninttype using at least 32 bits andlong, pointer, andoff_ttypes using at least 64 bits. ๐_POSIX_V7_ILP32_OFF32โ the implementation provides a C-language compilation environment with 32-bitint,long, pointer, andoff_ttypes. (yes bestie, it's the V7 twin of the V6 one, same energy, different number ๐)_POSIX_V7_ILP32_OFFBIGโ the implementation provides a C-language compilation environment with 32-bitint,long, and pointer types and anoff_ttype using at least 64 bits. ๐ซถ_POSIX_V7_LP64_OFF64โ the implementation provides a C-language compilation environment with 32-bitintand 64-bitlong, pointer, andoff_ttypes. ๐_POSIX_V7_LPBIG_OFFBIGโ the implementation provides a C-language compilation environment with aninttype using at least 32 bits andlong, pointer, andoff_ttypes using at least 64 bits. ๐ฅ_POSIX2_C_BINDโ supports the C-Language Binding option. This symbol shall always have the value200809L. no exceptions, no cap. ๐ฏ_POSIX2_C_DEVโ supports the C-Language Development Utilities option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value reported bysysconf()shall either be-1or200809L. ๐ ๏ธ_POSIX2_CHAR_TERMโ supports the Terminal Characteristics option. Heads up, this one's a lil different: the value of this symbol reported bysysconf()shall either be-1or a value greater than zero. ๐_POSIX2_FORT_DEVโ supports the FORTRAN Development Utilities option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐งโจ_POSIX2_FORT_RUNโ supports the FORTRAN Runtime Utilities option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. Thesysconf()value shall either be-1or200809L. ๐_POSIX2_LOCALEDEFโ supports the creation of locales by thelocaledefutility. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐_POSIX2_PBSโ supports the Batch Environment Services and Utilities option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value reported bysysconf()shall either be-1or200809L. ๐ฆ_POSIX2_PBS_ACCOUNTINGโ supports the Batch Accounting option. If defined in<unistd.h>, it shall be-1,0, or200809L.sysconf()shall report either-1or200809L. ๐งพ_POSIX2_PBS_CHECKPOINTโ supports the Batch Checkpoint/Restart option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L, and the value reported bysysconf()shall either be-1or200809L. ๐พ_POSIX2_PBS_LOCATEโ supports the Locate Batch Job Request option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐_POSIX2_PBS_MESSAGEโ supports the Batch Job Message Request option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value reported bysysconf()shall either be-1or200809L. โ๏ธ_POSIX2_PBS_TRACKโ supports the Track Batch Job Request option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐ฐ๏ธ_POSIX2_SW_DEVโ supports the Software Development Utilities option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. Thesysconf()value shall either be-1or200809L. ๐งฐ_POSIX2_UPEโ supports the User Portability Utilities option. If defined in<unistd.h>, it shall be-1,0, or200809L, andsysconf()shall report either-1or200809L. ๐งณ_XOPEN_CRYPTโ the implementation supports the X/Open Encryption Option Group. ๐_XOPEN_ENH_I18Nโ the implementation supports the Issue 4, Version 2 Enhanced Internationalization Option Group. This symbol shall always be set to a value other than-1. ๐บ๏ธ_XOPEN_REALTIMEโ the implementation supports the X/Open Realtime Option Group. โก_XOPEN_REALTIME_THREADSโ the implementation supports the X/Open Realtime Threads Option Group. ๐งต_XOPEN_SHMโ the implementation supports the Issue 4, Version 2 Shared Memory Option Group. This symbol shall always be set to a value other than-1. ๐ง โจ_XOPEN_STREAMSโ the implementation supports the XSI STREAMS Option Group. ๐_XOPEN_UNIXโ the implementation supports the XSI option. ๐ง_XOPEN_UUCPโ the implementation supports the UUCP Utilities option. If this symbol is defined in<unistd.h>, it shall be defined to be-1,0, or200809L. The value of this symbol reported bysysconf()shall be either-1or200809L. ๐
โฐ Execution-Time Symbolic Constants โฐ
okay okay, new category bestie, and the rules here are different so pay attention ๐
If any of the following symbolic constants are not defined in the <unistd.h> header, the value shall vary depending on the file to which it is applied. If defined, they shall have values suitable for use in #if preprocessing directives. yes, #if. the preprocessor wants in on this. ๐
If any of the following symbolic constants are defined to have value -1 in the <unistd.h> header, the implementation shall not provide the option on any file. But 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. it's giving all-or-nothing energy fr fr. ๐ค
All of the following values, whether they're defined as symbolic constants in <unistd.h> or not, may be queried with respect to a specific file using the pathconf() or fpathconf() functions. ๐ซถ
_POSIX_ASYNC_IOโ asynchronous input or output operations may be performed for the associated file. like, the file is doing its own thing in the background and honestly? good for it. ๐ฆโจ_POSIX_PRIO_IOโ prioritized input or output operations may be performed for the associated file. ๐_POSIX_SYNC_IOโ synchronized input or output operations may be performed for the associated file. โจ
If these next symbolic constants are defined in the <unistd.h> header, bestie, they apply to files and to all paths in all file systems on the implementation โ like, the whole vibe, everywhere:
_POSIX_TIMESTAMP_RESOLUTIONโ the resolution in nanoseconds for all file timestamps. โฑ๏ธ_POSIX2_SYMLINKSโ symbolic links can be created. ๐
โจ Constants for Functions โจ
The <unistd.h> header shall define NULL as described in <stddef.h>. (Yes, that NULL. The iconic one. ๐ซถ)
The <unistd.h> header shall define the following symbolic constants for use with the access() function. The values shall be suitable for use in #if preprocessing directives โ iykyk, they gotta work in the preprocessor:
F_OKโ test for existence of file. ๐R_OKโ test for read permission.W_OKโ test for write permission.X_OKโ test for execute (search) permission.
And 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. No duplicates, no cap. ๐ซ
The <unistd.h> header shall define the following symbolic constants for the confstr() function:
_CS_PATHโ this is the value for thePATHenvironment variable that finds all of the standard utilities that are provided in a manner accessible via theexecfamily of functions._CS_POSIX_V7_ILP32_OFF32_CFLAGSโ ifsysconf(_SC_V7_ILP32_OFF32)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to thec99utility to build an application using a programming model with 32-bitint,long, pointer, andoff_ttypes._CS_POSIX_V7_ILP32_OFF32_LDFLAGSโ ifsysconf(_SC_V7_ILP32_OFF32)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to thec99utility to build an application using a programming model with 32-bitint,long, pointer, andoff_ttypes._CS_POSIX_V7_ILP32_OFF32_LIBSโ ifsysconf(_SC_V7_ILP32_OFF32)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to thec99utility to build an application using a programming model with 32-bitint,long, pointer, andoff_ttypes._CS_POSIX_V7_ILP32_OFFBIG_CFLAGSโ ifsysconf(_SC_V7_ILP32_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to thec99utility to build an application using a programming model with 32-bitint,long, and pointer types, and anoff_ttype using at least 64 bits._CS_POSIX_V7_ILP32_OFFBIG_LDFLAGSโ ifsysconf(_SC_V7_ILP32_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to thec99utility to build an application using a programming model with 32-bitint,long, and pointer types, and anoff_ttype using at least 64 bits._CS_POSIX_V7_ILP32_OFFBIG_LIBSโ ifsysconf(_SC_V7_ILP32_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to thec99utility to build an application using a programming model with 32-bitint,long, and pointer types, and anoff_ttype using at least 64 bits._CS_POSIX_V7_LP64_OFF64_CFLAGSโ ifsysconf(_SC_V7_LP64_OFF64)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to thec99utility to build an application using a programming model with 32-bitintand 64-bitlong, pointer, andoff_ttypes._CS_POSIX_V7_LP64_OFF64_LDFLAGSโ ifsysconf(_SC_V7_LP64_OFF64)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to thec99utility to build an application using a programming model with 32-bitintand 64-bitlong, pointer, andoff_ttypes._CS_POSIX_V7_LP64_OFF64_LIBSโ ifsysconf(_SC_V7_LP64_OFF64)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to thec99utility to build an application using a programming model with 32-bitintand 64-bitlong, pointer, andoff_ttypes._CS_POSIX_V7_LPBIG_OFFBIG_CFLAGSโ ifsysconf(_SC_V7_LPBIG_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to thec99utility to build an application using a programming model with aninttype using at least 32 bits andlong, pointer, andoff_ttypes using at least 64 bits._CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGSโ ifsysconf(_SC_V7_LPBIG_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to thec99utility to build an application using a programming model with aninttype using at least 32 bits andlong, pointer, andoff_ttypes using at least 64 bits._CS_POSIX_V7_LPBIG_OFFBIG_LIBSโ ifsysconf(_SC_V7_LPBIG_OFFBIG)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of libraries to be given to thec99utility to build an application using a programming model with aninttype using at least 32 bits andlong, pointer, andoff_ttypes using at least 64 bits._CS_POSIX_V7_THREADS_CFLAGSโ ifsysconf(_SC_POSIX_THREADS)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of initial options to be given to thec99utility to build a multi-threaded application. These flags are in addition to those associated with any of the other_CS_POSIX_V7_*_CFLAGSvalues used to specify particular type size programing environments._CS_POSIX_V7_THREADS_LDFLAGSโ ifsysconf(_SC_POSIX_THREADS)returns-1, the meaning of this value is unspecified. Otherwise, this value is the set of final options to be given to thec99utility to build a multi-threaded application. These flags are in addition to those associated with any of the other_CS_POSIX_V7_*_LDFLAGSvalues used to specify particular type size programing environments._CS_POSIX_V7_WIDTH_RESTRICTED_ENVSโ this value is a<newline>-separated list of names of programming environments supported by the implementation in which the widths of theblksize_t,cc_t,mode_t,nfds_t,pid_t,ptrdiff_t,size_t,speed_t,ssize_t,suseconds_t,tcflag_t,wchar_t, andwint_ttypes are no greater than the width of typelong. The format of each name shall be suitable for use with thegetconf -voption. ๐_CS_V7_ENVโ this is the value that provides the environment variable information (other than that provided by_CS_PATH) that is required by the implementation to create a conforming environment, as described in the implementation's conformance documentation.
The following symbolic constants are reserved for compatibility with Issue 6 (legacy icons, we still love them ๐):
_CS_POSIX_V6_ILP32_OFF32_CFLAGS_CS_POSIX_V6_ILP32_OFF32_LDFLAGS_CS_POSIX_V6_ILP32_OFF32_LIBS_CS_POSIX_V6_ILP32_OFFBIG_CFLAGS_CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS_CS_POSIX_V6_ILP32_OFFBIG_LIBS_CS_POSIX_V6_LP64_OFF64_CFLAGS_CS_POSIX_V6_LP64_OFF64_LDFLAGS_CS_POSIX_V6_LP64_OFF64_LIBS_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS_CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS_CS_POSIX_V6_LPBIG_OFFBIG_LIBS_CS_POSIX_V6_WIDTH_RESTRICTED_ENVS_CS_V6_ENV
The <unistd.h> header shall define SEEK_CUR, SEEK_END, and SEEK_SET as described in <stdio.h>.
The <unistd.h> header shall define the following symbolic constants as possible values for the function argument to the lockf() function:
F_LOCKโ lock a section for exclusive use. ๐F_TESTโ test section for locks by other processes.F_TLOCKโ test and lock a section for exclusive use.F_ULOCKโ unlock locked sections. ๐
The <unistd.h> header shall define the following symbolic constants for pathconf():
_PC_2_SYMLINKS_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_MAX_XFER_SIZE_PC_REC_MIN_XFER_SIZE_PC_REC_XFER_ALIGN_PC_SYMLINK_MAX_PC_SYNC_IO_PC_TIMESTAMP_RESOLUTION_PC_VDISABLE
The <unistd.h> header shall define the following symbolic constants for sysconf():
okay bestie, deep breath, because here comes the rest of the sysconf() constants and there are, like, a hundred of them ๐
Not me counting. I counted. Every single one gets its moment, no skips, no cuts, we're doing the whole list:
_SC_2_C_BIND_SC_2_C_DEV_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_AIO_LISTIO_MAX_SC_AIO_MAX_SC_AIO_PRIO_DELTA_MAX_SC_ARG_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_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_SEM_NSEMS_MAX_SC_SEM_VALUE_MAX_SC_SEMAPHORES_SC_SHARED_MEMORY_OBJECTS_SC_SHELL_SC_SIGQUEUE_MAX_SC_SPAWN_SC_SPIN_LOCKS_SC_SPORADIC_SERVER_SC_SS_REPL_MAX_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_ROBUST_PRIO_INHERIT_SC_THREAD_ROBUST_PRIO_PROTECT_SC_THREAD_SAFE_FUNCTIONS_SC_THREAD_SPORADIC_SERVER_SC_THREAD_STACK_MIN_SC_THREAD_THREADS_MAX_SC_THREADS_SC_TIMEOUTS_SC_TIMER_MAX_SC_TIMERS_SC_TRACE_SC_TRACE_EVENT_FILTER_SC_TRACE_EVENT_NAME_MAX_SC_TRACE_INHERIT_SC_TRACE_LOG_SC_TRACE_NAME_MAX_SC_TRACE_SYS_MAX_SC_TRACE_USER_EVENT_MAX_SC_TTY_NAME_MAX_SC_TYPED_MEMORY_OBJECTS_SC_TZNAME_MAX_SC_V7_ILP32_OFF32_SC_V7_ILP32_OFFBIG_SC_V7_LP64_OFF64_SC_V7_LPBIG_OFFBIG_SC_V6_ILP32_OFF32_SC_V6_ILP32_OFFBIG_SC_V6_LP64_OFF64_SC_V6_LPBIG_OFFBIG_SC_VERSION_SC_XOPEN_CRYPT_SC_XOPEN_ENH_I18N_SC_XOPEN_REALTIME_SC_XOPEN_REALTIME_THREADS_SC_XOPEN_SHM_SC_XOPEN_STREAMS_SC_XOPEN_UNIX_SC_XOPEN_UUCP_SC_XOPEN_VERSION
we made it. icon behavior honestly ๐
Quick lil note on two of them: the two constants _SC_PAGESIZE and _SC_PAGE_SIZE may be defined to have the same value. That's it, that's the whole tea. ๐ต
๐ File Streams ๐
The <unistd.h> header shall define the following symbolic constants for file streams โ these are the ones you actually use every single day, bestie, no exaggeration:
STDERR_FILENOโ file number of stderr;2.STDIN_FILENOโ file number of stdin;0.STDOUT_FILENOโ file number of stdout;1.
๐ Terminal Special Characters ๐
And the <unistd.h> header shall define this symbolic constant for terminal special character handling:
_POSIX_VDISABLEโ this symbol shall be defined to be the value of a character that shall disable terminal special character handling, as described in Section 11.2.6, Special Control Characters. And this symbol shall always be set to a value other than-1. Periodt. ๐ซถ
๐ฆ Type Definitions ๐ฆ
The <unistd.h> header shall define the size_t, ssize_t, uid_t, gid_t, off_t, and pid_t types as described in <sys/types.h>.
The <unistd.h> header shall define the intptr_t type as described in <stdint.h>.
๐ Declarations ๐
Okay so here's the part where it just drops the whole roster. These following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided. Look at her, she's stunning:
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 *);
int dup(int);
int dup2(int, int);
void _exit(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 []);
int faccessat(int, const char *, int, int);
int fchdir(int);
int fchown(int, uid_t, gid_t);
int fchownat(int, const char *, uid_t, gid_t, int);
int fdatasync(int);
int fexecve(int, char *const [], char *const []);
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);
int isatty(int);
int lchown(const char *, uid_t, gid_t);
int link(const char *, const char *);
int linkat(int, const char *, int, const char *, int);
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);
ssize_t readlinkat(int, 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 *);
int symlinkat(const char *, int, 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);
int unlink(const char *);
int unlinkat(int, const char *, int);
ssize_t write(int, const void *, size_t);
Implementations may also include the pthread_atfork() prototype as defined in <pthread.h>. Implementations may also include the ctermid() prototype as defined in <stdio.h>.
And the <unistd.h> header shall declare these external variables โ yes, the getopt() girlies, they live here:
extern char *optarg;
extern int opterr, optind, optopt;
Inclusion of the <unistd.h> header may make visible all symbols from the headers <stddef.h>, <stdint.h>, and <stdio.h>.
heads up bestie: everything below this line is informative, not normative. Different vibe entirely. Still useful though! ๐ง
โจ APPLICATION USAGE โจ
So, the tea: POSIX.1โ2008 only describes the behavior of systems that claim conformance to it. But if you're an application developer who wants to write apps that adapt to other versions of this standard โ or to systems that don't conform to any POSIX standard at all โ you might find it useful to conditionally compile different code depending on the value of _POSIX_VERSION, like this:
#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 POSIX.1โ2008 and of the Single UNIX Specification can be identified by the following macros โ it's giving archaeology but make it โจ:
- POSIX.1โ1988 standard โ
_POSIX_VERSION==198808L - POSIX.1โ1990 standard โ
_POSIX_VERSION==199009L - ISO POSIXโ1:1996 standard โ
_POSIX_VERSION==199506L - Single UNIX Specification, Version 1 โ
_XOPEN_UNIXand_XOPEN_VERSION==4 - Single UNIX Specification, Version 2 โ
_XOPEN_UNIXand_XOPEN_VERSION==500 - ISO POSIXโ1:2001 and Single UNIX Specification, Version 3 โ
_POSIX_VERSION==200112L, plus (if the XSI option is supported)_XOPEN_UNIXand_XOPEN_VERSION==600
POSIX.1โ2008 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) < 200809L) {
fprintf(stderr, "POSIX.1-2008 system required, terminating \n");
exit(1);
}
and one last thing, bestie: new applications should not use_XOPEN_SHMor_XOPEN_ENH_I18N. Just don't. ๐
okay breathe, that was a lot of constants ๐ซถ we're still going though โ more to come โจ
๐ RATIONALE ๐
okay so picture this: as POSIX.1โ2008 evolved, certain options got so standardized that the standard developers were like โbestie, why are we even keeping this as an option? simply requiring one of the option choices was simpler than retaining the option.โ But for backwards-compatibility, the option flags โ with required constant values โ are retained. periodt. ๐
โจ Version Test Macros โจ
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 POSIX.1โ2008.
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. ๐
๐ง Compile-Time Symbolic Constants for System-Wide Options ๐ง
POSIX.1โ2008 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. POSIX.1โ2008 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 POSIX.1โ2008, 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 POSIX.1โ2008. ๐ญ๐
๐ฎ FUTURE DIRECTIONS ๐ฎ
None. literally nothing, bestie. the future is a blank canvas. ๐โจ
๐ SEE ALSO ๐
<limits.h><stddef.h><stdint.h><stdio.h><sys_socket.h><sys_types.h><termios.h><wctype.h>
The System Interfaces volume of POSIX.1โ2017, access(), alarm(), chown(), close(), confstr(), crypt(), ctermid(), dup(), _Exit(), encrypt(), exec, fchdir(), fchown(), fdatasync(), fork(), fpathconf(), fsync(), ftruncate(), getcwd(), getegid(), geteuid(), getgid(), getgroups(), gethostid(), gethostname(), getlogin(), getopt(), getpgid(), getpgrp(), getpid(), getppid(), getsid(), getuid(), isatty(), lchown(), link(), lockf(), lseek(), nice(), pause(), pipe(), read(), readlink(), rmdir(), setegid(), seteuid(), setgid(), setpgid(), setpgrp(), setregid(), setreuid(), setsid(), setuid(), sleep(), swab(), symlink(), sync(), sysconf(), tcgetpgrp(), tcsetpgrp(), truncate(), ttyname(), unlink(), write()
๐ COPYRIGHT ๐
okay legal bestie moment, no cap, hereโs the whole copyright tea:
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
thatโs the whole page, bestie! this one came from IEEE/The Open Group, dated 2017, and itโs the unistd.h(7POSIX) page. mwah ๐โจ๐ฆ
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms