Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fchdir - change current directory

&pagelevel(4)&pagelevel

Syntax

#include <unistd.h>

int fchdir(int fildes); 

Description

Like chdir(), fchdir() also changes the current directory. The new directory is identified
by the file descriptor fildes. The current directory is the starting point for the search for
pathnames which do not begin with “/“. The fildes argument is an open file descriptor
referencing a directory.
To make a directory the current directory, a process must have execute (search) permission
for the directory.

Return val.

0

-1

if successful.

if an error occurs. The current working directory remains unchanged.
errno is set to indicate the error.

Errors

fchdir() will fail if:

 

EACCES

There is no search permission for fildes.

 

EBADF

fildes is not a file descriptor for an open file.

 

ENOTDIR

The open file descriptor does not point to a directory.

 

EINTR

A signal was caught during the fchdir() system call.

 

EIO

An I/O error occurred during reading or writing from the file system.

 

ENOLINK

fildes refers to a remote computer and the link to this computer is no longer active.

Notes

The change of the current directory is effective for the duration of the current program (or
of the current shell). If a new program or shell is started, the home directory is again set as
the current directory.
To make a directory the current directory, a process must have execute permission (search)
for the directory.
fchdir() is only effective in the currently active process and only until the active program
terminates.
fchdir() is only executed for POSIX files.

See also

chdir(), chroot(), unistd.h.