chdir(), fchdir() - change current working directory
#include <unistd.h>
int chdir (const char *path)
int fchdir (int fildes)
The chdir(2) and fchdir(2) calls change the current working directory of a process.
For chdir(2), the path argument points to the pathname of a directory. For fchdir(2), the fildes argument is a file descriptor specifying a directory.
Both functions cause the named directory to become the current
working directory, that is, the starting point for path searches of
pathnames not beginning with a slash, (
/
In order for a directory to become the current directory, a process must have execute (search) access to the directory.
Upon successfully completing, both chdir(2) and fchdir(2) return 0. Otherwise, they return -1 and errno to indicate the error.
The chdir(2) call will fail and the current working directory will be unchanged if one or more of the following are true:
The fchdir(2) function will fail for these reasons: