# Unistd.h

In the C and C++ programming languages, unistd.h is the name of the header file that provides access to the POSIX operating system API. It is defined by the POSIX.1 standard, the base of the Single Unix Specification, and should therefore be available in any POSIX-compliant operating system and compiler. For instance, this includes Unix and Unix-like operating systems, such as GNU variants, distributions of Linux and BSD, and macOS, and compilers such as GCC and LLVM.
On Unix-like systems, the interface defined by unistd.h is typically made up largely of system call wrapper functions such as fork, pipe and I/O primitives (read, write, close, etc.).
Unix compatibility layers such as Cygwin and MinGW also provide their own versions of unistd.h. In fact, those systems provide it along with the translation libraries that implement its functions in terms of win32 functions. E.g. In Cygwin, a header file can be found in /usr/include that sub-includes a file of the same name in /usr/include/sys. Not everything is defined in there but some definitions are done by references to the GNU C standard library headers (like stddef.h) which provide the type size_t and many more. Thus, unistd.h is only a generically defined adaptive layer that might be based upon already existing system and compiler specific definitions. This has the general advantage of not having a possibly concurrent set of header file defined, but one that is built upon the same root which, for this reason, will raise much fewer concerns in combined usage cases.

## Overview of functions

| | Function | Description |
| | crypt | password and data encryption |
| | encrypt | encrypt 64-byte messages |
| | gethostid | get the unique identifier of the current host |
| | gethostname | get hostname |
| | getopt | parse command-line options |
| | swab | swap adjacent bytes |
| | sysconf | get configuration at run time |
| Signals | alarm | schedule an alarm signal |
| Signals | pause | wait for signal |
| Filesystem | access faccessat faccessat2 | check user's permissions for a file or whether it exists |
| Filesystem | chdir fchdir | change working directory |
| Filesystem | chown fchown lchown fchownat | change owner and group of a file |
| Filesystem | close | close a file descriptor |
| Filesystem | dup dup2 | duplicate a file descriptor |
| Filesystem | fsync fdatasync | synchronize a file's in-core state with storage device |
| Filesystem | fpathconf pathconf | get configuration values for files |
| Filesystem | ftruncate truncate | truncate a file to a specified length |
| Filesystem | getcwd getwd get_current_dir_name | get current working directory |
| Filesystem | isatty | test whether a file descriptor refers to a terminal |
| Filesystem | link linkat | make a new name for a file |
| Filesystem | lockf | apply, test or remove a POSIX lock on an open file |
| Filesystem | lseek | reposition read/write file offset |
| Filesystem | pipe pipe2 | create pipe |
| Filesystem | pread pwrite | read from or write to a file descriptor at a given offset |
| Filesystem | read | read from a file descriptor |
| Filesystem | readlink readlinkat | read value of a symbolic link |
| Filesystem | rmdir | delete a directory |
| Filesystem | symlink symlinkat | make a new name for a file |
| Filesystem | sync syncfs | commit filesystem caches to disk |
| Filesystem | ttyname ttyname_r | return name of a terminal |
| Filesystem | unlink unlinkat | delete a name and possibly the file it refers to |
| Filesystem | write | write to a file descriptor |
| Process | _exit | terminate the calling process |
| Process | execl execlp execle execv execvp execvpe | execute a file |
| Process | fexecve | execute program specified via file descriptor |
| Process | fork | create a new process |
| Process | setpgid getpgid setpgrp getpgrp | set/get process group |
| Process | getpid getppid | get process identification |
| Process | getsid | get session ID |
| Process | nice | change process priority |
| Process | setsid | creates a session and sets the process group ID |
| Process | sleep | sleep for a specified number of seconds |
| Process | tcgetpgrp tcsetpgrp | get and set terminal foreground process group |
| User/Group | getgid getegid | get group identity |
| User/Group | getuid geteuid | get user identity |
| User/Group | getgroups | get list of supplementary group IDs |
| User/Group | getlogin getlogin_r | get username |
| User/Group | seteuid setegid | set effective user or group ID |
| User/Group | setgid | set group identity |
| User/Group | setreuid setregid | set real and/or effective user or group ID |
| User/Group | setuid | set user identity |