![]() |
![]() |
getcwd
- Get Current Working Directory FunctionThe left arrow above will return you to
the Home page
The left arrows below will return you to the Previous page
![]() |
![]() |
![]() |
#include <unistd.h> char *getcwd(char *buf, size_t size); Returns: buf if OK, NULL on error |
Every process has a current working directory which can be set using chdir. While chdir can use a relative pathname argument, there is a need for a function to derive the absolute pathname of the directory. getcwd performs this function.
The function is passed the address of a buffer, buf, and its size. The buffer must be large enough to accommodate the full absolute pathname plus a terminating NULL byte, or an error is returned.
Some implementations of getcwd allow the first argument buf to be NULL. In which case the function calls malloc to allocate size number of bytes dynamically. This is not part of the POSIX standard and should be avoided.
Enter the man getcwd command on your system to get a more detailed description of this function.
The descriptions of the system functions above are drawn from sources that include
man
uals on the Sun Solaris system and the MAC OS X Darwin/BDS system, and also from 'Advanced Programming in the UNIX Environment', W. Richard Stevens, Addison-Wesley, 1993.
![]() |
![]() |
![]() |
For use only by students and instructors using the supplementary material available with the text book: "Operating Systems - Internals and Design Principles", William Stallings, Prentice Hall, 5th Edition, 2004. Not to be printed out or copied by any other persons or used for any other purpose without written permission of the author(s).
©