Section: Linux Programmer's Manual (2)
Return to Main Contents
getcwd - get current working directory
* This page documents the getcwd(2) system call, which
* is not defined in any user-space header files; you should
* use getcwd(3) defined in <unistd.h> instead in applications.
long getcwd(char *buf, unsigned long size);
function copies an absolute pathname of the
current working directory to the array pointed to by
which is of length
If the current absolute path name would require a buffer
is returned, and
an application should check for this error,
and allocate a larger buffer if necessary.
is NULL, the behaviour of
on failure (for example, if the current directory is not readable), with
set accordingly, and the number of characters stored in
on success. The contents of the array pointed to by
is undefined on error.
Note that this return value differs from the
library function, which returns
on failure and the address of
if user memory cannot be mapped
if directory does not exist (i.e. it has been deleted)
if not enough space available for storing the path
if memory access violation occurs while copying
system call is Linux specific, use the
C library function for portability.
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
linux.jgfs.net manual pages