xref: /freebsd/lib/libsys/chdir.2 (revision 8e95079e175854b84e57c521b34b4b52f7ae9cb1)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd March 30, 2020
29.Dt CHDIR 2
30.Os
31.Sh NAME
32.Nm chdir ,
33.Nm fchdir
34.Nd change current working directory
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In unistd.h
39.Ft int
40.Fn chdir "const char *path"
41.Ft int
42.Fn fchdir "int fd"
43.Sh DESCRIPTION
44The
45.Fa path
46argument points to the pathname of a directory.
47The
48.Fn chdir
49system call
50causes the named directory
51to become the current working directory, that is,
52the starting point for path searches of pathnames not beginning with
53a slash,
54.Ql / .
55.Pp
56The
57.Fn fchdir
58system call
59causes the directory referenced by
60.Fa fd
61to become the current working directory,
62the starting point for path searches of pathnames not beginning with
63a slash,
64.Ql / .
65.Pp
66In order for a directory to become the current directory,
67a process must have execute (search) access to the directory.
68.Sh RETURN VALUES
69.Rv -std
70.Sh ERRORS
71The
72.Fn chdir
73system call
74will fail and the current working directory will be unchanged if
75one or more of the following are true:
76.Bl -tag -width Er
77.It Bq Er ENOTDIR
78A component of the path prefix is not a directory.
79.It Bq Er ENAMETOOLONG
80A component of a pathname exceeded 255 characters,
81or an entire path name exceeded 1023 characters.
82.It Bq Er ENOENT
83The named directory does not exist.
84.It Bq Er ELOOP
85Too many symbolic links were encountered in translating the pathname.
86.It Bq Er EACCES
87Search permission is denied for any component of
88the path name.
89.It Bq Er EFAULT
90The
91.Fa path
92argument
93points outside the process's allocated address space.
94.It Bq Er EIO
95An I/O error occurred while reading from or writing to the file system.
96.It Bq Er EINTEGRITY
97Corrupted data was detected while reading from the file system.
98.El
99.Pp
100The
101.Fn fchdir
102system call
103will fail and the current working directory will be unchanged if
104one or more of the following are true:
105.Bl -tag -width Er
106.It Bq Er EACCES
107Search permission is denied for the directory referenced by the
108file descriptor.
109.It Bq Er ENOTDIR
110The file descriptor does not reference a directory.
111.It Bq Er EBADF
112The argument
113.Fa fd
114is not a valid file descriptor.
115.El
116.Sh SEE ALSO
117.Xr chroot 2
118.Sh STANDARDS
119The
120.Fn chdir
121system call is expected to conform to
122.St -p1003.1-90 .
123.Sh HISTORY
124The
125.Fn chdir
126system call appeared in
127.At v1 .
128The
129.Fn fchdir
130system call appeared in
131.Bx 4.2 .
132