getcwd(3C)getcwd(3C)NAMEgetcwd() - get pathname of current working directory
SYNOPSISDESCRIPTION
The function places the absolute pathname of the current working direc‐
tory in the array pointed to by buf, and returns buf. The value of
size must be at least one greater than the length of the pathname to be
returned.
If buf is a NULL pointer, obtains size bytes of space using (see mal‐
loc(3C)). In this case, the pointer returned by can be used as the
argument in a subsequent call to (see malloc(3C)). Invoking with buf
as a null pointer is not recommended because this functionality may be
removed from the HP-UX operating system in a future release.
RETURN VALUE
Upon successful completion, returns a pointer to the current directory
pathname. Otherwise, it returns NULL with set if size is not large
enough, or if an error occurs in a lower-level function.
ERRORS
fails if any of the following conditions are encountered:
The size argument is zero.
The size argument is greater than zero, but is
smaller than the length of the pathname.
The length of the specified pathname exceeds
bytes, or the length of a component of the
pathname exceeds bytes while is in effect.
may fail if any of the following conditions are encountered:
Read or search permission is denied for a component of pathname.
buf points outside the allocated address space
of the process. may not always detect this
error.
failed to provide size bytes of memory.
EXAMPLES
#include <unistd.h>
#include <limits.h>
char *cwd;
char buf[PATH_MAX+1];
...
if ((cwd = getcwd(buf, PATH_MAX+1)) == NULL) {
perror("pwd");
exit(1);
}
puts(cwd);
AUTHOR
was developed by AT&T.
SEE ALSOpwd(1), malloc(3C), thread_safety(5).
STANDARDS CONFORMANCEgetcwd(3C)