-.\" Hey Emacs! This file is -*- nroff -*- source.
-.\"
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\"
+.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
.\"
.\" Modified by Michael Haardt <michael@moria.de>
.\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
.\" Added 'fchdir'. Fixed bugs in error section.
.\" Modified 1996-10-21 by Eric S. Raymond <esr@thyrsus.com>
.\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
-.\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
+.\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
.\"
-.TH CHDIR 2 2007-06-18 "Linux" "Linux Programmer's Manual"
+.TH CHDIR 2 2019-08-02 "Linux" "Linux Programmer's Manual"
.SH NAME
chdir, fchdir \- change working directory
.SH SYNOPSIS
.B #include <unistd.h>
-.sp
+.PP
.BI "int chdir(const char *" path );
.br
.BI "int fchdir(int " fd );
+.PP
+.in -4n
+Feature Test Macro Requirements for glibc (see
+.BR feature_test_macros (7)):
+.in
+.PP
+.BR fchdir ():
+.PD 0
+.ad l
+.RS 4
+_XOPEN_SOURCE\ >=\ 500
+.\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+ || /* Since glibc 2.12: */ _POSIX_C_SOURCE\ >=\ 200809L
+ || /* Glibc up to and including 2.19: */ _BSD_SOURCE
+.RE
+.ad
+.PD
.SH DESCRIPTION
.BR chdir ()
-changes the current working directory pf the calling process to the
+changes the current working directory of the calling process to the
directory specified in
.IR path .
.PP
.BR chdir ();
the only difference is that the directory is given as an
open file descriptor.
-.SH "RETURN VALUE"
+.SH RETURN VALUE
On success, zero is returned.
On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
-Depending on the file system, other errors can be returned.
+Depending on the filesystem, other errors can be returned.
The more
general errors for
.BR chdir ()
is too long.
.TP
.B ENOENT
-The file does not exist.
+The directory specified in
+.I path
+does not exist.
.TP
.B ENOMEM
Insufficient kernel memory was available.
.B EBADF
.I fd
is not a valid file descriptor.
-.SH "CONFORMING TO"
-SVr4, 4.4BSD, POSIX.1-2001.
+.TP
+.B ENOTDIR
+.I fd
+does not refer to a directory.
+.SH CONFORMING TO
+POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
.SH NOTES
The current working directory is the starting point for interpreting
-relative pathnames (those not starting with '/').
-
+relative pathnames (those not starting with \(aq/\(aq).
+.PP
A child process created via
.BR fork (2)
inherits its parent's current working directory.
The current working directory is left unchanged by
.BR execve (2).
-
-The prototype for
-.BR fchdir ()
-is only available if
-.B _BSD_SOURCE
-is defined, or
-.B _XOPEN_SOURCE
-is defined with the value 500.
-.SH "SEE ALSO"
+.SH SEE ALSO
.BR chroot (2),
.BR getcwd (3),
.BR path_resolution (7)