chdir()

NAME

chdir(), fchdir() - change current working directory

SYNOPSIS

#include <unistd.h>

int chdir (const char *path) int fchdir (int fildes)

DESCRIPTION

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.

RETURN VALUES

Upon successfully completing, both chdir(2) and fchdir(2) return 0. Otherwise, they return -1 and errno to indicate the error.

ERRORS

The chdir(2) call will fail and the current working directory will be unchanged if one or more of the following are true:

[EINVAL]
The pathname contains a character with the high-order bit set.
[ENOTDIR]
A component of the path prefix is not a directory.
[ENAMETOOLONG]
A component of a pathname exceeded {NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.
[ENOENT]
The named directory does not exist.
[ELOOP]
Too many symbolic links were encountered in translating the pathname.
[EACCES]
Search permission is denied for any component of the pathname.

The fchdir(2) function will fail for these reasons:

[EACCES]
The process does not have search permission for the directory indicated by fildes.
[EBADF]
The fildes argument isn't an open file descriptor.
[EINTR]
The call was interrupted by a signal.
[EIO]
There was an I/O error while reading from the filesystem.
[ENOTDIR]
The file descriptor fildes does not point to a directory.