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