man-pages/man2/chdir.2.html
2021-03-31 01:06:50 +01:00

221 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of CHDIR</TITLE>
</HEAD><BODY>
<H1>CHDIR</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-08-02<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
chdir, fchdir - change working directory
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<P>
<B>int chdir(const char *</B><I>path</I><B>);</B>
<BR>
<B>int fchdir(int </B><I>fd</I><B>);</B>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>fchdir</B>():
<DL COMPACT><DT id="1"><DD>
_XOPEN_SOURCE&nbsp;&gt;=&nbsp;500
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Since&nbsp;glibc&nbsp;2.12:&nbsp;*/&nbsp;_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200809L
<BR>&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;/*&nbsp;Glibc&nbsp;up&nbsp;to&nbsp;and&nbsp;including&nbsp;2.19:&nbsp;*/&nbsp;_BSD_SOURCE
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>chdir</B>()
changes the current working directory of the calling process to the
directory specified in
<I>path</I>.
<P>
<B>fchdir</B>()
is identical to
<B>chdir</B>();
the only difference is that the directory is given as an
open file descriptor.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, zero is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
Depending on the filesystem, other errors can be returned.
The more
general errors for
<B>chdir</B>()
are listed below:
<DL COMPACT>
<DT id="2"><B>EACCES</B>
<DD>
Search permission is denied for one of the components of
<I>path</I>.
(See also
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7).)
<DT id="3"><B>EFAULT</B>
<DD>
<I>path</I>
points outside your accessible address space.
<DT id="4"><B>EIO</B>
<DD>
An I/O error occurred.
<DT id="5"><B>ELOOP</B>
<DD>
Too many symbolic links were encountered in resolving
<I>path</I>.
<DT id="6"><B>ENAMETOOLONG</B>
<DD>
<I>path</I>
is too long.
<DT id="7"><B>ENOENT</B>
<DD>
The directory specified in
<I>path</I>
does not exist.
<DT id="8"><B>ENOMEM</B>
<DD>
Insufficient kernel memory was available.
<DT id="9"><B>ENOTDIR</B>
<DD>
A component of
<I>path</I>
is not a directory.
</DL>
<P>
The general errors for
<B>fchdir</B>()
are listed below:
<DL COMPACT>
<DT id="10"><B>EACCES</B>
<DD>
Search permission was denied on the directory open on
<I>fd</I>.
<DT id="11"><B>EBADF</B>
<DD>
<I>fd</I>
is not a valid file descriptor.
<DT id="12"><B>ENOTDIR</B>
<DD>
<I>fd</I>
does not refer to a directory.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SVr4, 4.4BSD.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
The current working directory is the starting point for interpreting
relative pathnames (those not starting with '/').
<P>
A child process created via
<B><A HREF="/cgi-bin/man/man2html?2+fork">fork</A></B>(2)
inherits its parent's current working directory.
The current working directory is left unchanged by
<B><A HREF="/cgi-bin/man/man2html?2+execve">execve</A></B>(2).
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+chroot">chroot</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+getcwd">getcwd</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+path_resolution">path_resolution</A></B>(7)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="13"><A HREF="#lbAB">NAME</A><DD>
<DT id="14"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="15"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="16"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="17"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="18"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="19"><A HREF="#lbAH">NOTES</A><DD>
<DT id="20"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="21"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:32 GMT, March 31, 2021
</BODY>
</HTML>