fanotify_mark.2: ERRORS: add missing EBADF error for invalid 'dirfd'
[man-pages.git] / man2 / chdir.2
blobc12ab12d5e1625c241459d8055119a20a37d1d7d
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 2021-03-22 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 chdir, fchdir \- change working directory
36 .SH SYNOPSIS
37 .nf
38 .B #include <unistd.h>
39 .PP
40 .BI "int chdir(const char *" path );
41 .BI "int fchdir(int " fd );
42 .fi
43 .PP
44 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .PP
49 .BR fchdir ():
50 .nf
51     _XOPEN_SOURCE >= 500
52 .\"    || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
53         || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
54         || /* Glibc up to and including 2.19: */ _BSD_SOURCE
55 .fi
56 .SH DESCRIPTION
57 .BR chdir ()
58 changes the current working directory of the calling process to the
59 directory specified in
60 .IR path .
61 .PP
62 .BR fchdir ()
63 is identical to
64 .BR chdir ();
65 the only difference is that the directory is given as an
66 open file descriptor.
67 .SH RETURN VALUE
68 On success, zero is returned.
69 On error, \-1 is returned, and
70 .I errno
71 is set to indicate the error.
72 .SH ERRORS
73 Depending on the filesystem, other errors can be returned.
74 The more
75 general errors for
76 .BR chdir ()
77 are listed below:
78 .TP
79 .B EACCES
80 Search permission is denied for one of the components of
81 .IR path .
82 (See also
83 .BR path_resolution (7).)
84 .TP
85 .B EFAULT
86 .I path
87 points outside your accessible address space.
88 .TP
89 .B EIO
90 An I/O error occurred.
91 .TP
92 .B ELOOP
93 Too many symbolic links were encountered in resolving
94 .IR path .
95 .TP
96 .B ENAMETOOLONG
97 .I path
98 is too long.
99 .TP
100 .B ENOENT
101 The directory specified in
102 .I path
103 does not exist.
105 .B ENOMEM
106 Insufficient kernel memory was available.
108 .B ENOTDIR
109 A component of
110 .I path
111 is not a directory.
113 The general errors for
114 .BR fchdir ()
115 are listed below:
117 .B EACCES
118 Search permission was denied on the directory open on
119 .IR fd .
121 .B EBADF
122 .I fd
123 is not a valid file descriptor.
125 .B ENOTDIR
126 .I fd
127 does not refer to a directory.
128 .SH CONFORMING TO
129 POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
130 .SH NOTES
131 The current working directory is the starting point for interpreting
132 relative pathnames (those not starting with \(aq/\(aq).
134 A child process created via
135 .BR fork (2)
136 inherits its parent's current working directory.
137 The current working directory is left unchanged by
138 .BR execve (2).
139 .SH SEE ALSO
140 .BR chroot (2),
141 .BR getcwd (3),
142 .BR path_resolution (7)