chdir

Changes the current working directory to the specified directory.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <unistd.h> 
   
  int chdir (
     const char  *path);
  

Parameters

path

(IN) Specifies the buffer containing the directory path.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

1

ENOENT

A component of path does not name an existing file or path is an empty string.

6

EACCES

Search permission is denied on a component of the path.

65

ENAMETOOLONG

The length of the path parameter exceeds maximum path length, or a path component is longer than maximum name length.

67

ENOTDIR

A component of the path is not a directory.

Remarks

The chdir function causes the directory named by the path parameter to become the current working directory for all threads of a virtual machine. It becomes the starting point for path searches for pathnames not beginning with “/”.

The path parameter can be either relative to the current working directory or it can be an absolute pathname.

See Also