getwd() — Get the current working directory

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <unistd.h>

char *getwd(char *path_name);

General description

The getwd() function determines an absolute path name of the current working directory of the calling process, and copies that path name into the array pointed to by path_name argument.

If the length of the path name of the current working directory is greater than (PATH_MAX+1) including the NULL byte, getwd() fails and returns a NULL pointer.

For portability to implementations conforming to earlier versions of the standards, getcwd() is preferred over this function.

Note: The getwd() function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and may be withdrawn in a future version. The getcwd() function is preferred for portability.

Returned value

If successful, getwd() returns a pointer to the string containing the absolute path name of the current working directory.

If unsuccessful, getwd() returns a NULL pointer and the contents of the array pointed to by path_name are undefined.

There are no errno values defined.

Related information