Commit | Line | Data |
---|---|---|
aaea5b2e KB |
1 | .\" Copyright (c) 1980, 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
be16c266 | 3 | .\" |
931b8415 | 4 | .\" %sccs.include.redist.man% |
be16c266 | 5 | .\" |
653ba8b6 | 6 | .\" @(#)chdir.2 8.2 (Berkeley) %G% |
931b8415 CL |
7 | .\" |
8 | .Dd | |
9 | .Dt CHDIR 2 | |
10 | .Os BSD 4 | |
11 | .Sh NAME | |
12 | .Nm chdir , | |
13 | .Nm fchdir | |
14 | .Nd change current working directory | |
15 | .Sh SYNOPSIS | |
16 | .Fd #include <unistd.h> | |
17 | .Ft int | |
18 | .Fn chdir "const char *path" | |
19 | .Ft int | |
20 | .Fn fchdir "int fd" | |
21 | .Sh DESCRIPTION | |
22 | The | |
23 | .Fa path | |
653ba8b6 | 24 | argument points to the pathname of a directory. |
931b8415 CL |
25 | The |
26 | .Fn chdir | |
27 | function | |
28 | causes the named directory | |
29 | to become the current working directory, that is, | |
30 | the starting point for path searches of pathnames not beginning with | |
31 | a slash, | |
32 | .Ql / . | |
33 | .Pp | |
34 | The | |
35 | .Fn fchdir | |
36 | function | |
e28eab18 | 37 | causes the directory referenced by |
931b8415 | 38 | .Fa fd |
e28eab18 | 39 | to become the current working directory, |
931b8415 CL |
40 | the starting point for path searches of pathnames not beginning with |
41 | a slash, | |
42 | .Ql / . | |
43 | .Pp | |
9726efd6 KM |
44 | In order for a directory to become the current directory, |
45 | a process must have execute (search) access to the directory. | |
931b8415 | 46 | .Sh RETURN VALUES |
9726efd6 | 47 | Upon successful completion, a value of 0 is returned. |
931b8415 CL |
48 | Otherwise, a value of -1 is returned and |
49 | .Va errno | |
50 | is set to indicate | |
9726efd6 | 51 | the error. |
931b8415 CL |
52 | .Sh ERRORS |
53 | .Fn Chdir | |
9726efd6 KM |
54 | will fail and the current working directory will be unchanged if |
55 | one or more of the following are true: | |
931b8415 CL |
56 | .Bl -tag -width Er |
57 | .It Bq Er ENOTDIR | |
b5984ffe | 58 | A component of the path prefix is not a directory. |
931b8415 | 59 | .It Bq Er EINVAL |
b5984ffe | 60 | The pathname contains a character with the high-order bit set. |
931b8415 | 61 | .It Bq Er ENAMETOOLONG |
b5984ffe KM |
62 | A component of a pathname exceeded 255 characters, |
63 | or an entire path name exceeded 1023 characters. | |
931b8415 | 64 | .It Bq Er ENOENT |
b5984ffe | 65 | The named directory does not exist. |
931b8415 | 66 | .It Bq Er ELOOP |
b5984ffe | 67 | Too many symbolic links were encountered in translating the pathname. |
931b8415 | 68 | .It Bq Er EACCES |
9726efd6 KM |
69 | Search permission is denied for any component of |
70 | the path name. | |
931b8415 CL |
71 | .It Bq Er EFAULT |
72 | .Fa Path | |
9726efd6 | 73 | points outside the process's allocated address space. |
931b8415 | 74 | .It Bq Er EIO |
fd690c8b | 75 | An I/O error occurred while reading from or writing to the file system. |
931b8415 CL |
76 | .El |
77 | .Pp | |
78 | .Fn Fchdir | |
e28eab18 KM |
79 | will fail and the current working directory will be unchanged if |
80 | one or more of the following are true: | |
931b8415 CL |
81 | .Bl -tag -width Er |
82 | .It Bq Er EACCES | |
1267c1ec KB |
83 | Search permission is denied for the directory referenced by the |
84 | file descriptor. | |
931b8415 | 85 | .It Bq Er ENOTDIR |
e28eab18 | 86 | The file descriptor does not reference a directory. |
931b8415 | 87 | .It Bq Er EBADF |
1267c1ec | 88 | The argument |
931b8415 | 89 | .Fa fd |
1267c1ec | 90 | is not a valid file descriptor. |
931b8415 CL |
91 | .El |
92 | .Sh SEE ALSO | |
93 | .Xr chroot 2 | |
94 | .Sh STANDARDS | |
95 | .Fn Chdir | |
96 | is expected to conform to IEEE Std 1003.1-1988 | |
97 | .Pq Dq Tn POSIX . | |
98 | .Sh HISTORY | |
99 | The | |
100 | .Fn fchdir | |
101 | function call | |
102 | appeared in | |
103 | .Bx 4.2 . |