[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

chdir Subroutine

Purpose

Changes the current directory.

Library

Standard C Library (libc.a)

Syntax

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

Description

The chdir subroutine changes the current directory to the directory indicated by the Path parameter.

Parameters

Path A pointer to the path name of the directory. If the Path parameter refers to a symbolic link, the chdir subroutine sets the current directory to the directory pointed to by the symbolic link. If Network File System (NFS) is installed on the system, this path can cross into another node.

The current directory, also called the current working directory, is the starting point of searches for path names that do not begin with a / (slash). The calling process must have search access to the directory specified by the Path parameter.

Return Values

Upon successful completion, the chdir subroutine returns a value of 0. Otherwise, a value of -1 is returned and the errno global variable is set to identify the error.

Error Codes

The chdir subroutine fails and the current directory remains unchanged if one or more of the following are true:

EACCES Search access is denied for the named directory.
ENOENT The named directory does not exist.
ENOTDIR The path name is not a directory.

The chdir subroutine can also be unsuccessful for other reasons. See "Base Operating System Error Codes for Services That Require Path-Name Resolution" for a list of additional error codes.

The chdir subroutine can also be unsuccessful for other reasons. See "Appendix A. Base Operating System Error Codes for Services That Require Path-Name Resolution" for a list of additional error codes.

If NFS is installed on the system, the chdir subroutine can also fail if the following is true:

ETIMEDOUT The connection timed out.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The chroot subroutine.

The cd command.

Base Operating System Error Codes for Services That Require Path-Name Resolution .

Files, Directories, and File Systems for Programmers in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]