]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man2/chdir.2
xnu-344.tar.gz
[apple/xnu.git] / bsd / man / man2 / chdir.2
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
50 The
51 .Fa path
52 argument points to the pathname of a directory.
53 The
54 .Fn chdir
55 function
56 causes the named directory
57 to become the current working directory, that is,
58 the starting point for path searches of pathnames not beginning with
59 a slash,
60 .Ql / .
61 .Pp
62 The
63 .Fn fchdir
64 function
65 causes the directory referenced by
66 .Fa fd
67 to become the current working directory,
68 the starting point for path searches of pathnames not beginning with
69 a slash,
70 .Ql / .
71 .Pp
72 In order for a directory to become the current directory,
73 a process must have execute (search) access to the directory.
74 .Sh RETURN VALUES
75 Upon successful completion, a value of 0 is returned.
76 Otherwise, a value of -1 is returned and
77 .Va errno
78 is set to indicate
79 the error.
80 .Sh ERRORS
81 .Fn Chdir
82 will fail and the current working directory will be unchanged if
83 one or more of the following are true:
84 .Bl -tag -width Er
85 .It Bq Er ENOTDIR
86 A component of the path prefix is not a directory.
87 .It Bq Er ENAMETOOLONG
88 A component of a pathname exceeded
89 .Dv {NAME_MAX}
90 characters, or an entire path name exceeded
91 .Dv {PATH_MAX}
92 characters.
93 .It Bq Er ENOENT
94 The named directory does not exist.
95 .It Bq Er ELOOP
96 Too many symbolic links were encountered in translating the pathname.
97 .It Bq Er EACCES
98 Search permission is denied for any component of
99 the path name.
100 .It Bq Er EFAULT
101 .Fa Path
102 points outside the process's allocated address space.
103 .It Bq Er EIO
104 An I/O error occurred while reading from or writing to the file system.
105 .El
106 .Pp
107 .Fn Fchdir
108 will fail and the current working directory will be unchanged if
109 one or more of the following are true:
110 .Bl -tag -width Er
111 .It Bq Er EACCES
112 Search permission is denied for the directory referenced by the
113 file descriptor.
114 .It Bq Er ENOTDIR
115 The file descriptor does not reference a directory.
116 .It Bq Er EBADF
117 The argument
118 .Fa fd
119 is not a valid file descriptor.
120 .El
121 .Sh SEE ALSO
122 .Xr chroot 2
123 .Sh STANDARDS
124 The
125 .Fn chdir
126 is expected to conform to
127 .St -p1003.1-88 .
128 .Sh HISTORY
129 The
130 .Fn fchdir
131 function call
132 appeared in
133 .Bx 4.2 .