xref: /original-bsd/lib/libc/sys/chdir.2 (revision b4971bb3)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)chdir.2	8.1 (Berkeley) 06/04/93
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
37causes the directory referenced by
38.Fa fd
39to become the current working directory,
40the starting point for path searches of pathnames not beginning with
41a slash,
42.Ql / .
43.Pp
44In order for a directory to become the current directory,
45a process must have execute (search) access to the directory.
46.Sh RETURN VALUES
47Upon successful completion, a value of 0 is returned.
48Otherwise, a value of -1 is returned and
49.Va errno
50is set to indicate
51the error.
52.Sh ERRORS
53.Fn Chdir
54will fail and the current working directory will be unchanged if
55one or more of the following are true:
56.Bl -tag -width Er
57.It Bq Er ENOTDIR
58A component of the path prefix is not a directory.
59.It Bq Er EINVAL
60The pathname contains a character with the high-order bit set.
61.It Bq Er ENAMETOOLONG
62A component of a pathname exceeded 255 characters,
63or an entire path name exceeded 1023 characters.
64.It Bq Er ENOENT
65The named directory does not exist.
66.It Bq Er ELOOP
67Too many symbolic links were encountered in translating the pathname.
68.It Bq Er EACCES
69Search permission is denied for any component of
70the path name.
71.It Bq Er EFAULT
72.Fa Path
73points outside the process's allocated address space.
74.It Bq Er EIO
75An I/O error occurred while reading from or writing to the file system.
76.El
77.Pp
78.Fn Fchdir
79will fail and the current working directory will be unchanged if
80one or more of the following are true:
81.Bl -tag -width Er
82.It Bq Er EACCES
83Search permission is denied for the directory referenced by the
84file descriptor.
85.It Bq Er ENOTDIR
86The file descriptor does not reference a directory.
87.It Bq Er EBADF
88The argument
89.Fa fd
90is not a valid file descriptor.
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 .
104