chdir, fchdir - 작업 디렉토리를 바꾼다.
#include <unistd.h>
int chdir(const char *path);
int fchdir(int fd);
fchdir():
_XOPEN_SOURCE >= 500
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
|| /* glibc up to and including 2.19: */ _BSD_SOURCE chdir() changes the current working directory of the calling process to the directory specified in path.
fchdir() is identical to chdir(); 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 errno is set to indicate the error.
파일 시스템에 의존적이며, 다른 에러가 리턴될 수 있다. chdir()에서 발생하는 일반적인 에러는 다음과 같다:
- EACCES
- Search permission is denied for one of the components of path. (See also path_resolution(7)EN.)
- EFAULT
- path가 접근할 수 없는 메모리 영역을 가리키고 있다.
- EIO
- I/O 에러가 발생했다.
- ELOOP
- path를 찾아갈 때, 너무 많은 심볼릭 링크가 존재한다.
- ENAMETOOLONG
- path 가 너무 길다.
- ENOENT
- The directory specified in path does not exist.
- ENOMEM
- 이용할수 있는 커널 메모리가 충분하지 않다.
- ENOTDIR
- path가 디렉토리가 아니다.
fchdir()에서 발생하는 일반적인 에러는 다음과 같다:
- EACCES
- fd로 지정된 디렉토리를 여는데 허가가 거부되었다.
- EBADF
- fd가 유효한 파일 기술자가 아니다.
- ENOTDIR
- fd does not refer to a directory.
POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
The current working directory is the starting point for interpreting relative pathnames (those not starting with '/').
A child process created via fork(2)EN inherits its parent's current working directory. The current working directory is left unchanged by execve(2)EN.