Unix for Beginners
Unix Shell Programming
Unix Useful References
Unix Useful Resources
© 2013 TutorialsPoint.COM
getcwd() - Unix, Linux System Call
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);
getcwd() function copies an absolute pathname of the
current working directory to the array pointed to by
buf, which is of length
If the current absolute path name would require a buffer
-1 is returned, and
ERANGE; an application should check for this error,
and allocate a larger buffer if necessary.
buf is NULL, the behaviour of
getcwd() is undefined.
-1 on failure (for example, if the current directory is not readable), with
errno set accordingly, and the number of characters stored in
buf on success. The contents of the array pointed to by
buf is undefined on error.
Note that this return value differs from the
library function, which returns
NULL on failure and the address of
buf on success.
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
getcwd system call is Linux specific, use the
getcwd C library function for portability.