FAT | RFS | XFS | ZFS

chdir()

PROTOTYPE

#include <posix.h>

int chdir(const char *path);

DESCRIPTION

chdir() changes the CWD to the directory specified by path. Paths starting with ‘/’ are absolute, otherwise they are relative to the CWD. If an error occurs, the CWD is unchanged.

The caller needs execute access to every directory in the path.

If successful, chdir() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No execute access to a path directory.
EFAULT path equals NULL.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a directory that was not found.
ENOTDIR One of the path components is not a directory.

EXAMPLE

/*---------------------------------------------------------------*/
/* Change current working directory to specified path.           */
/*---------------------------------------------------------------*/
if (chdir(path))
{
  perror("chdir() failed");
  return -1;
}