CHDIR(2) | System Calls Manual | CHDIR(2) |
chdir
, fchdir
— change current working directory
#include
<unistd.h>
int
chdir
(const
char *path);
int
fchdir
(int
fd);
The path argument points to the pathname of
a directory. The
chdir
()
function causes the named directory to become the current working directory,
that is, the starting point for path searches of pathnames not beginning
with a slash (‘/
’).
The
fchdir
()
function causes the directory referenced by fd to
become the current working directory, the starting point for path searches
of pathnames not beginning with a slash
(‘/
’).
In order for a directory to become the current directory, a process must have execute (search) access to the directory.
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
chdir
() will fail and the current working
directory will be unchanged if one or more of the following are true:
ENOTDIR
]ENAMETOOLONG
]NAME_MAX
characters, or an entire pathname (including the terminating NUL) exceeded
PATH_MAX
bytes.ENOENT
]ELOOP
]EACCES
]EFAULT
]EIO
]fchdir
() will fail and the current working
directory will be unchanged if one or more of the following are true:
The chdir
() and
fchdir
() functions are expected to conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
The chdir
() system call first appeared in
Version 1 AT&T UNIX, and
fchdir
() in 4.3BSD-Reno.
September 10, 2015 | OpenBSD-6.1 |