]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/chdir.2
Many pages: Use correct letter case in page titles (TH)
[thirdparty/man-pages.git] / man2 / chdir.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" Modified by Michael Haardt <michael@moria.de>
6 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
7 .\" Modified 1995-04-15 by Michael Chastain <mec@shell.portal.com>:
8 .\" Added 'fchdir'. Fixed bugs in error section.
9 .\" Modified 1996-10-21 by Eric S. Raymond <esr@thyrsus.com>
10 .\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
11 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
12 .\"
13 .TH chdir 2 (date) "Linux man-pages (unreleased)"
14 .SH NAME
15 chdir, fchdir \- change working directory
16 .SH LIBRARY
17 Standard C library
18 .RI ( libc ", " \-lc )
19 .SH SYNOPSIS
20 .nf
21 .B #include <unistd.h>
22 .PP
23 .BI "int chdir(const char *" path );
24 .BI "int fchdir(int " fd );
25 .fi
26 .PP
27 .RS -4
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
30 .RE
31 .PP
32 .BR fchdir ():
33 .nf
34 _XOPEN_SOURCE >= 500
35 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
36 || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
37 || /* Glibc up to and including 2.19: */ _BSD_SOURCE
38 .fi
39 .SH DESCRIPTION
40 .BR chdir ()
41 changes the current working directory of the calling process to the
42 directory specified in
43 .IR path .
44 .PP
45 .BR fchdir ()
46 is identical to
47 .BR chdir ();
48 the only difference is that the directory is given as an
49 open file descriptor.
50 .SH RETURN VALUE
51 On success, zero is returned.
52 On error, \-1 is returned, and
53 .I errno
54 is set to indicate the error.
55 .SH ERRORS
56 Depending on the filesystem, other errors can be returned.
57 The more
58 general errors for
59 .BR chdir ()
60 are listed below:
61 .TP
62 .B EACCES
63 Search permission is denied for one of the components of
64 .IR path .
65 (See also
66 .BR path_resolution (7).)
67 .TP
68 .B EFAULT
69 .I path
70 points outside your accessible address space.
71 .TP
72 .B EIO
73 An I/O error occurred.
74 .TP
75 .B ELOOP
76 Too many symbolic links were encountered in resolving
77 .IR path .
78 .TP
79 .B ENAMETOOLONG
80 .I path
81 is too long.
82 .TP
83 .B ENOENT
84 The directory specified in
85 .I path
86 does not exist.
87 .TP
88 .B ENOMEM
89 Insufficient kernel memory was available.
90 .TP
91 .B ENOTDIR
92 A component of
93 .I path
94 is not a directory.
95 .PP
96 The general errors for
97 .BR fchdir ()
98 are listed below:
99 .TP
100 .B EACCES
101 Search permission was denied on the directory open on
102 .IR fd .
103 .TP
104 .B EBADF
105 .I fd
106 is not a valid file descriptor.
107 .TP
108 .B ENOTDIR
109 .I fd
110 does not refer to a directory.
111 .SH STANDARDS
112 POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
113 .SH NOTES
114 The current working directory is the starting point for interpreting
115 relative pathnames (those not starting with \(aq/\(aq).
116 .PP
117 A child process created via
118 .BR fork (2)
119 inherits its parent's current working directory.
120 The current working directory is left unchanged by
121 .BR execve (2).
122 .SH SEE ALSO
123 .BR chroot (2),
124 .BR getcwd (3),
125 .BR path_resolution (7)