# <unistd.h> The <unistd.h> header defines the symbolic constants and structures which are not already defined or declared in some other header. > > > int access(const char \*path, int mode); [POSIX] unsigned int > alarm(unsigned int seconds); [POSIX] char \*getcwd(char \*buf, size\_t > size); [POSIX] pid\_t getpid(void); [POSIX] > > > char \*getwd(char \*path\_name); [POSIX] > > > int isatty(int fd); [POSIX] > > > void swab(const void \*src, void \*dest, size\_t len); [POSIX] > > > long int sysconf(int name); [POSIX] > > > int unlink(const char \*path); [POSIX] > > > extern char \*optarg; extern int optind; extern int optopt; extern > int opterr; extern int optreset; > > > int getopt(int argc, char \* const argv[], const char \*optstring); > > > [POSIX] > > > access > > > int access(const char \*path, int mode); [POSIX] The access function checks the accessibility of the file named by path for the access permissions indicated by mode. The value of mode is the bitwise inclusive OR of the access permissions to be checked (R\_OK for read permission, W\_OK for write permission and X\_OK for execute/search permission) or the existence test, F\_OK. All components of the pathname path are checked for access permissions (including F\_OK). When Hexagon standalone programs execute on a simulator that is running on the Windows Operating system, the check for X\_OK is not supported due to restrictions in the Windows platform. The real user ID is used in place of the effective user ID and the real group access list (including the real group ID) are used in place of the effective ID for verifying permission. If a process has super-user privileges and indicates success for R\_OK or W\_OK, the file may not actually have read or write permission bits set. If a process has super-user privileges and indicates success for X\_OK, at least one of the user, group, or other execute bits is set. (However, the file may still not be executable.) If path cannot be found or if an access modes would not be granted, a -1 value is returned; otherwise a 0 value is returned. ## alarm > > > unsigned int alarm(unsigned int seconds); [POSIX] The alarm function sets a timer to deliver the signal SIGALRM to the calling process seconds after the call to alarm. If an alarm has already been set with alarm but has not been delivered, another call to alarm will supersede the prior call. The request alarm(0) voids the current alarm and the signal SIGALRM will not be delivered. The maximum number of seconds allowed is 2,147,483,647. The return value of alarm is the amount of time left on the timer from a previous call to alarm. If no alarm is currently set, the return value is 0. If there is an error setting the timer, alarm returns ((unsigned int) -1). ## getcwd > > > char \*getcwd(char \*buf, size\_t size); [POSIX] The function copies the absolute pathname of the current working directory into the memory referenced by buf and returns a pointer to buf. The size argument is the size, in bytes, of the array referenced by buf. If buf is NULL, space is allocated as necessary to store the pathname. This space can later be freed with free. Upon successful completion, a pointer to the pathname is returned. Otherwise a NULL pointer is returned and the global variable errno is set to indicate the error. In addition, getwd copies the error message associated with errno into the memory referenced by buf. ## getopt > > > extern char \*optarg; extern int optind; extern int optopt; extern > int opterr; extern int optreset; > > > int getopt(int argc, char \* const argv[], const char \*optstring); > > > [POSIX] The function incrementally parses a command line argument list argv and returns the next known option character. An option character is known if it has been specified in the string of accepted option characters, optstring. The option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option argument is to follow. For example, an option string “x” recognizes an option “-x”, and an option string “x:” recognizes an option and argument “-x argument”. It does not matter to getopt if a following argument has leading whitespace. On return from getopt, optarg points to an option argument, if it is anticipated, and the variable optind contains the index to the next argv argument for a subsequent call to getopt. The variable optopt saves the last known option character returned The variables opterr and optind are both initialized to 1. The optind variable can be set to another value before a set of calls to getopt in order to skip over more or less argv entries. To use getopt to evaluate multiple sets of arguments, or to evaluate a single set of arguments multiple times, the variable optreset must be set to 1 before the second and each additional set of calls to getopt, and the variable optind must be reinitialized. The getopt function returns -1 when the argument list is exhausted. The interpretation of options in the argument list can be canceled by the option – (double dash) which causes getopt to signal the end of argument processing and return -1. When all options have been processed (up to the first non-option argument), getopt returns -1. The getopt function returns the next known option character in optstring. If getopt encounters a character not found in optstring or if it detects a missing option argument, it returns “?” (question mark). If optstring has a leading “:”. a missing option argument causes “:” to be returned instead of “?”. In either case, the variable optopt is set to the character that caused the error. The getopt function returns -1 when the argument list is exhausted. For example: > > > extern char \*optarg; extern int optind; int bflag, ch, fd; > > > bflag = 0; > > > while ((ch = getopt(argc, argv, “bf:”)) != -1) { switch (ch) { > > > case ‘b’: bflag = 1; break; > > > case ‘f’: > > > if ((fd = open(optarg, O\_RDONLY, 0)) < 0) { (void)fprintf(stderr, > > > “myname: %s: %s\n”, optarg, strerror(errno)); exit(1); > > > } > > > break; > > > case ‘?’: default: > > > usage(); > > > } > > > } > > > argc -= optind; argv += optind; If the getopt function encounters a character not found in the string optstring or detects a missing option argument it writes an error message to stderr and returns “?”. Setting opterr to a zero disables these error messages. If optstring has a leading “:”, a missing option argument causes a “:” to be returned in addition to suppressing any error messages. Option arguments are allowed to begin with “-”; this is reasonable but reduces the amount of error checking possible. Bugs The getopt function was once specified to return EOF instead of -1. This was changed by IEEE Std. 1003.2-1992 (“POSIX.2”) to decouple getopt from <stdio.h>. A single dash (“-”) can be specified as a character in optstring, however it should never have an argument associated with it. This allows getopt to be used with programs that expect “-” as an option flag. This practice is wrong, and should not be used in any current development. It is provided for backwards compatibility only. Care should be taken not to use “-” as the first character in optstring to avoid a semantic conflict with GNU getopt, which assigns different meaning to an optstring that begins with a “-”. By default, a single dash causes getopt to return -1. It is also possible to handle digits as option letters. This allows getopt to be used with programs that expect a number (“-3”) as an option. This practice is wrong, and should not be used in any current development. It is provided for backward compatibility only. The following code fragment works in most cases. > > > int ch; > > > long length; char \*p; > > > while ((ch = getopt(argc, argv, “0123456789”)) != -1) { switch (ch) { > > > case ‘0’: case ‘1’: case ‘2’: case ‘3’: case ‘4’: > > > case ‘5’: case ‘6’: case ‘7’: case ‘8’: case ‘9’: p = argv[optind - > 1]; > > > if (p[0] == ‘-’ && p[1] == ch && !p[2]) length = ch - ‘0’; > > > else > > > length = strtol(argv[optind] + 1, NULL, 10); break; > > > } > > > } ## getpid > > > pid\_t getpid(void); [POSIX] The function returns the process ID of the calling process. The ID is guaranteed to be unique and is useful for constructing temporary file names. When programs are compiled in standalone mode there is no job control. When the getpid routine is called the return value will be the thread number the program is executing on. ## getwd > > > char \*getwd(char \*path\_name); [POSIX] > > > The function is a compatibility routine that calls getcwd with its > buf argument and a size of MAXPATHLEN (as defined in the include file > <sys/param.h>). Obviously, buf should be at least MAXPATHLEN bytes in > length. These routines have traditionally been used by programs to save the name of a working directory for the purpose of returning to it. A much faster and less error-prone method of accomplishing this is to open the current directory (.) and use the fchdir function to return. Upon successful completion, a pointer to the pathname is returned. Otherwise a NULL pointer is returned and the global variable errno is set to indicate the error. In addition, getwd copies the error message associated with errno into the memory referenced by buf. Because getwd does not know the length of the supplied buffer, it is possible for a long (but valid) path to overflow the buffer and provide a means for an attacker to exploit the caller. getcwd should be used in place of getwd (the latter is only provided for compatibility purposes). ## isatty > > > int isatty(int fd); [POSIX] The function determines if the file descriptor fd refers to a valid terminal type device. The function returns 1 if fd is associated with a terminal device; otherwise it returns 0 and errno is set to indicate the error. ## swab > > > void swab(const void \*src, void \*dest, size\_t len); [POSIX] The function copies len bytes from the location referenced by src to the location referenced by dest, swapping adjacent bytes. The argument len must be even number. ## sysconf > > > long int sysconf(int name); [POSIX] The function provides a method for applications to determine the current value of a configurable system limit or option variable. The name argument specifies the system variable to be queried. Symbolic constants for each name value are found in the include file > > > <unistd.h>. > > > [Table 11-12](https://docs.qualcomm.com/doc/80-N3040-23/topic/c_posix_unistd.html#_bookmark790) lists the sysconf values. > > > **Table 11-12 sysconf values** | **Value** | **Description** | | --- | --- | | \_SC\_ARG\_MAX | The maximum bytes of argument to execve(2). | | \_SC\_ATEXIT\_MAX | - The maximum number of functions that can be registered with
- atexit(3). | | \_SC\_BARRIERS | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Barriers
- option to which the system attempts to conform, otherwise -1. | | \_SC\_CLOCK\_SELECTION | - Return the POSIX version the implementation of the Clock
- Selection Option on this system conforms to, or -1 if
unavailable. | | \_SC\_CHILD\_MAX | The maximum number of simultaneous processes per user ID. | | \_SC\_CLK\_TCK | The number of clock ticks per second. | | \_SC\_FSYNC | - Return 1 if the File Synchronization Option is available on this
- system, otherwise -1. | | \_SC\_HOST\_NAME\_MAX | The maximum size of a hostname, including NULL. | | \_SC\_IOV\_MAX | - The maximum number of iovec structures that a process has
- available for use with preadv(2), pwritev(2), readv(2),
recvmsg(2), sendmsg(2) or writev(2). | | \_SC\_JOB\_CONTROL | - Return 1 if job control is available on this system, otherwise
- -1. | | \_SC\_LOGIN\_NAME\_MAX | - Returns the size of the storage required for a login name, in
- bytes, including the terminating NUL. | | \_SC\_MAPPED\_FILES | - Return 1 if the Memory Mapped Files Option is available on this
- system, otherwise -1. | | \_SC\_MEMLOCK | - Return 1 if the Process Memory Locking Option is available on
- this system, otherwise -1. | | \_SC\_MEMLOCK\_RANGE | - Return 1 if the Range Memory Locking Option is available on this
- system, otherwise -1. | | \_SC\_MEMORY\_PROTECTION | - Return 1 if the Memory Protection Option is available on this
- system, otherwise -1. | | \_SC\_MONOTONIC\_CLOCK | - Return the POSIX version the implementation of the Monotonic
- Clock Option on this system conforms to, or -1 if unavailable. | | \_SC\_NGROUPS\_MAX | The maximum number of supplemental groups. | | \_SC\_OPEN\_MAX | The maximum number of open files per process. | | \_SC\_PAGESIZE | The size of a system page in bytes. | | \_SC\_PASS\_MAX | The maximum length of the password, not counting NULL. | | \_SC\_READER\_WRITER\_LOCKS | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Read-Write
- Locks option to which the system attempts to conform, otherwise
-1. | | \_SC\_REGEXP | - Return 1 if POSIX regular expressions are available on this
- system, otherwise -1. | | \_SC\_SEMAPHORES | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Semaphores
- option to which the system attempts to conform, otherwise -1.


Availability of the Semaphores option depends on the
P1003\_1B\_SEMAPHORE kernel option. | | \_SC\_SHELL | - Return 1 if POSIX shell is available on this system, otherwise
- -1. | > > > **Table 11-12 sysconf values** | **Value** | **Description** | | --- | --- | | \_SC\_SPIN\_LOCKS | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Spin Locks
- option to which the system attempts to conform, otherwise -1. | | \_SC\_STREAM\_MAX | - The minimum maximum number of streams that a process may have
- open at any one time. | | \_SC\_SYMLOOP\_MAX | - The maximum number of symbolic links that can be expanded in a
- path name. | | \_SC\_SYNCHRONIZED\_IO | - Return 1 if the Synchronized I/O Option is available on this
- system, otherwise -1. | | \_SC\_THREADS | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Threads
- option to which the system attempts to conform, otherwise -1. | | \_SC\_TIMERS | - The version of IEEE Std. 1003.1 (“POSIX.1”) and its Timers
- option to which the system attempts to conform, otherwise -1. | | \_SC\_TZNAME\_MAX | - The minimum maximum number of types supported for the name of a
- timezone. | | \_SC\_SAVED\_IDS | - Returns 1 if saved set-group and saved set-user ID is available,
- otherwise -1. | | \_SC\_VERSION | - The version of ISO/IEC 9945 (POSIX 1003.1) with which the system
- attempts to comply. | | \_SC\_XOPEN\_SHM | - Return 1 if the X/Open Portability Guide Issue 4, Version 2
- (“XPG4.2”) Shared Memory option is available on this system,
otherwise -1. Availability of the Shared Memory option depends
on the SYSVSHM kernel option. | | \_SC\_BC\_BASE\_MAX | The maximum ibase/obase values in the bc(1) utility. | | \_SC\_BC\_DIM\_MAX | The maximum array size in the bc(1) utility. | | \_SC\_BC\_SCALE\_MAX | The maximum scale value in the bc(1) utility. | | \_SC\_BC\_STRING\_MAX | The maximum string length in the bc(1) utility. | | \_SC\_COLL\_WEIGHTS\_MAX | - The maximum number of weights that can be assigned to any entry
- of the LC\_COLLATE order keyword in the locale definition file. | | \_SC\_EXPR\_NEST\_MAX | - The maximum number of expressions that can be nested within
- parenthesis by the expr(1) utility. | | \_SC\_LINE\_MAX | - The maximum length in bytes of a text-processing utility’s input
- line. | | \_SC\_RE\_DUP\_MAX | - The maximum number of repeated occurrences of a regular
- expression permitted when using interval notation. | | \_SC\_2\_VERSION | - The version of POSIX 1003.2 with which the system attempts to
- comply. | | \_SC\_2\_C\_BIND | - Return 1 if the system’s C-language development facilities sup-
- port the C-Language Bindings Option, otherwise -1. | | \_SC\_2\_C\_DEV | - Return 1 if the system supports the C-Language Development
- Utilities Option, otherwise -1. | | \_SC\_2\_CHAR\_TERM | - Return 1 if the system supports at least one terminal type
- capable of all operations described in POSIX 1003.2, otherwise
-1. | | \_SC\_2\_FORT\_DEV | - Return 1 if the system supports the FORTRAN Development
- Utilities Option, otherwise -1. | > > > **Table 11-12 sysconf values** | **Value** | **Description** | | --- | --- | | \_SC\_2\_FORT\_RUN | - Return 1 if the system supports the FORTRAN Runtime Utilities
- Option, otherwise -1. | | \_SC\_2\_LOCALEDEF | - Return 1 if the system supports the creation of locales, other-
- wise -1. | | \_SC\_2\_SW\_DEV | - Return 1 if the system supports the Software Development
- Utilities Option, otherwise -1. | | \_SC\_2\_UPE | - Return 1 if the system supports the User Portability Utilities
- Option, otherwise -1. | | \_SC\_GETGR\_R\_SIZE\_MAX | - The minimum size of the buffer passed to getgrgid\_r(3) and
- getgrnam\_r(3). | | \_SC\_GETPW\_R\_SIZE\_MAX | - The minimum size of the buffer passed to getpwnam\_r(3) and
- getpwuid\_r(3). | | \_SC\_NPROCESSORS\_CONF | The number of processors configured. | | \_SC\_NPROCESSORS\_ONLN | The number of processors online (capable of running processes). | If the call to sysconf is not successful, -1 is returned and errno is set appropriately. Otherwise, if the variable is associated with functionality that is not supported, -1 is returned and errno is not modified. Otherwise, the current variable value is returned. ## unlink > > > int unlink(const char \*path); [POSIX] The function removes a link to a file. If path names a symbolic link, unlink removes the symbolic link and does not affect any file or directory named by the contents of the symbolic link. Otherwise, unlink removes the link named by path and decrements the link count of the file referenced by the link. When the file’s link count becomes 0 and no process has the file open, the space occupied by the file will be freed and the file is no longer accessible. If one or more processes have the file open when the last link is removed, the link is removed before unlink returns, but the removal of the file contents is postponed until all references to the file are closed. The path argument must not name a directory unless the process has appropriate privileges and the implementation supports using unlink on directories. Upon successful completion, unlink marks for update the st\_ctime and st\_mtime fields of the parent directory. If the file’s link count is not 0, the st\_ctime field of the file is marked for update. Upon successful completion, 0 is returned. Otherwise, -1 is returned, errno is set to indicate the error, and the file is not unlinked. Last Published: Oct 06, 2026 Previous Topic [Next Topic Dinkum C++ Library](https://docs.qualcomm.com/bundle/publicresource/80-N3040-23/topics/cpp_index.md)