getcwd()

NAME

getcwd() - get working directory pathname

SYNOPSIS

#include <unistd.h>

char * getcwd (char *buf, size_t size)

DESCRIPTION

The getcwd(2) 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.

This routine has traditionally been used by programs to save the name of a working directory for the purpose of returning to it.

RETURN VALUES

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.

If an error occurs, the contents of buf are not changed.

ERRORS

The getcwd(2) function will fail if:

[EINVAL]
The size argument is zero.
[ENOENT]
A component of the pathname no longer exists.
[ENOMEM]
Insufficient memory is available.
[ERANGE]
The size argument is greater than zero but smaller than the length of the pathname plus 1.

SEE ALSO

chdir(2)