Name: _____________________ Class: CET 421
SSN/ID:   _____________________ Section & Group: ____________
Reference: getcwd function


#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 manuals 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.

 


Ricky J. Sethi <rickys at sethi.org>
Last modified: Mon Jun 6 01:16:21 PDT 2005