char *getcwd(char *buf, size_t size);
IEEE Std 1003.1-2017
The purpose is to get the
pathname of the current working directory. The
getcwd() function shall place an absolute
pathname of the current working directory in the array pointed to by
buf, and return buf. The
pathname shall contain no components that are dot or dot-dot, or are symbolic links.
If there are multiple
getcwd() could place in the array pointed to by buf, one beginning with a
<slash> character and one or more beginning with two
<slash> characters, then
getcwd() shall place the
pathname beginning with a single
<slash> character in the array. The
pathname shall not contain any unnecessary
characters after the leading one or two
The size argument is the size in bytes of the character array pointed to by the buf argument. If buf is a
null pointer, the behavior of
getcwd() is unspecified.
Upon successful completion,
getcwd() shall return the buf argument. Otherwise,
getcwd() shall return a
null pointer and set
errno to indicate the error. The contents of the array pointed to by buf are then undefined.
getcwd() function shall fail if:
EINVAL- The size argument is
ERANGE- The size argument is greater than
0, but is smaller than the length of the
string + 1.
getcwd() function may fail if:
EACCES- Search permission was denied for the current directory, or read or search permission was denied for a directory above the current directory in the file hierarchy.
ENOMEM- Insufficient storage space is available.