OSDN Git Service

d97f00ed00d3dd4dacefda641af0ae33aa089c5d
[linuxjm/LDP_man-pages.git] / original / man2 / chdir.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1995-04-15 by Michael Chastain <mec@shell.portal.com>:
28 .\"   Added 'fchdir'. Fixed bugs in error section.
29 .\" Modified 1996-10-21 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\"
33 .TH CHDIR 2 2010-11-25 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 chdir, fchdir \- change working directory
36 .SH SYNOPSIS
37 .B #include <unistd.h>
38 .sp
39 .BI "int chdir(const char *" path );
40 .br
41 .BI "int fchdir(int " fd );
42 .sp
43 .in -4n
44 Feature Test Macro Requirements for glibc (see
45 .BR feature_test_macros (7)):
46 .in
47 .sp
48 .BR fchdir ():
49 .PD 0
50 .ad l
51 .RS 4
52 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
53 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
54 .br
55 || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
56 .RE
57 .ad
58 .PD
59 .SH DESCRIPTION
60 .BR chdir ()
61 changes the current working directory of the calling process to the
62 directory specified in
63 .IR path .
64 .PP
65 .BR fchdir ()
66 is identical to
67 .BR chdir ();
68 the only difference is that the directory is given as an
69 open file descriptor.
70 .SH RETURN VALUE
71 On success, zero is returned.
72 On error, \-1 is returned, and
73 .I errno
74 is set appropriately.
75 .SH ERRORS
76 Depending on the filesystem, other errors can be returned.
77 The more
78 general errors for
79 .BR chdir ()
80 are listed below:
81 .TP
82 .B EACCES
83 Search permission is denied for one of the components of
84 .IR path .
85 (See also
86 .BR path_resolution (7).)
87 .TP
88 .B EFAULT
89 .I path
90 points outside your accessible address space.
91 .TP
92 .B EIO
93 An I/O error occurred.
94 .TP
95 .B ELOOP
96 Too many symbolic links were encountered in resolving
97 .IR path .
98 .TP
99 .B ENAMETOOLONG
100 .I path
101 is too long.
102 .TP
103 .B ENOENT
104 The file does not exist.
105 .TP
106 .B ENOMEM
107 Insufficient kernel memory was available.
108 .TP
109 .B ENOTDIR
110 A component of
111 .I path
112 is not a directory.
113 .PP
114 The general errors for
115 .BR fchdir ()
116 are listed below:
117 .TP
118 .B EACCES
119 Search permission was denied on the directory open on
120 .IR fd .
121 .TP
122 .B EBADF
123 .I fd
124 is not a valid file descriptor.
125 .SH CONFORMING TO
126 SVr4, 4.4BSD, POSIX.1-2001.
127 .SH NOTES
128 The current working directory is the starting point for interpreting
129 relative pathnames (those not starting with \(aq/\(aq).
130
131 A child process created via
132 .BR fork (2)
133 inherits its parent's current working directory.
134 The current working directory is left unchanged by
135 .BR execve (2).
136 .SH SEE ALSO
137 .BR chroot (2),
138 .BR getcwd (3),
139 .BR path_resolution (7)
140 .SH COLOPHON
141 This page is part of release 3.67 of the Linux
142 .I man-pages
143 project.
144 A description of the project,
145 information about reporting bugs,
146 and the latest version of this page,
147 can be found at
148 \%http://www.kernel.org/doc/man\-pages/.