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