Section: Linux Programmer's Manual (2)
Return to Main Contents
chdir, fchdir - change working directory
int chdir(const char *path);
int fchdir(int fd);
Feature Test Macro Requirements for glibc (see
- Since glibc 2.12:
_BSD_SOURCE || _XOPEN_SOURCE >= 500 ||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED ||
_POSIX_C_SOURCE >= 200809L
- Before glibc 2.12:
_BSD_SOURCE || _XOPEN_SOURCE >= 500
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
changes the current working directory of the calling process to the
directory specified in
is identical to
the only difference is that the directory is given as an
open file descriptor.
On success, zero is returned.
On error, -1 is returned, and
is set appropriately.
Depending on the file system, other errors can be returned.
general errors for
are listed below:
Search permission is denied for one of the components of
points outside your accessible address space.
An I/O error occurred.
Too many symbolic links were encountered in resolving
is too long.
The file does not exist.
Insufficient kernel memory was available.
A component of
is not a directory.
The general errors for
are listed below:
Search permission was denied on the directory open on
is not a valid file descriptor.
SVr4, 4.4BSD, POSIX.1-2001.
The current working directory is the starting point for interpreting
relative pathnames (those not starting with '/').
A child process created via
inherits its parent's current working directory.
The current working directory is left unchanged by
The prototype for
is only available if
is defined, or
is defined with the value 500.
This page is part of release 3.27 of the Linux
A description of the project,
and information about reporting bugs,
can be found at
- RETURN VALUE
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.