244 lines
5.4 KiB
HTML
244 lines
5.4 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of OPENDIR</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>OPENDIR</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
opendir, fdopendir - open a directory
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>></B>
|
|
<B>#include <<A HREF="file:///usr/include/dirent.h">dirent.h</A>></B>
|
|
|
|
<B>DIR *opendir(const char *</B><I>name</I><B>);</B>
|
|
<B>DIR *fdopendir(int </B><I>fd</I><B>);</B>
|
|
</PRE>
|
|
|
|
<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>fdopendir</B>():
|
|
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
<DL COMPACT>
|
|
<DT id="2">Since glibc 2.10:<DD>
|
|
_POSIX_C_SOURCE >= 200809L
|
|
<DT id="3">Before glibc 2.10:<DD>
|
|
_GNU_SOURCE
|
|
</DL>
|
|
</DL>
|
|
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>opendir</B>()
|
|
|
|
function opens a directory stream corresponding to the
|
|
directory <I>name</I>, and returns a pointer to the directory stream.
|
|
The stream is positioned at the first entry in the directory.
|
|
<P>
|
|
|
|
The
|
|
<B>fdopendir</B>()
|
|
|
|
function
|
|
is like
|
|
<B>opendir</B>(),
|
|
|
|
but returns a directory stream for the directory referred
|
|
to by the open file descriptor
|
|
<I>fd</I>.
|
|
|
|
After a successful call to
|
|
<B>fdopendir</B>(),
|
|
|
|
<I>fd</I>
|
|
|
|
is used internally by the implementation,
|
|
and should not otherwise be used by the application.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>opendir</B>()
|
|
|
|
and
|
|
<B>fdopendir</B>()
|
|
|
|
functions return a pointer to the directory stream.
|
|
On error, NULL is returned, and
|
|
<I>errno</I>
|
|
|
|
is set appropriately.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="4"><B>EACCES</B>
|
|
|
|
<DD>
|
|
Permission denied.
|
|
<DT id="5"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>fd</I>
|
|
|
|
is not a valid file descriptor opened for reading.
|
|
<DT id="6"><B>EMFILE</B>
|
|
|
|
<DD>
|
|
The per-process limit on the number of open file descriptors has been reached.
|
|
<DT id="7"><B>ENFILE</B>
|
|
|
|
<DD>
|
|
The system-wide limit on the total number of open files has been reached.
|
|
<DT id="8"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
Directory does not exist, or <I>name</I> is an empty string.
|
|
<DT id="9"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient memory to complete the operation.
|
|
<DT id="10"><B>ENOTDIR</B>
|
|
|
|
<DD>
|
|
<I>name</I> is not a directory.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>fdopendir</B>()
|
|
|
|
is available in glibc since version 2.4.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>opendir</B>(),
|
|
|
|
<B>fdopendir</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>opendir</B>()
|
|
|
|
is present on SVr4, 4.3BSD, and specified in POSIX.1-2001.
|
|
<B>fdopendir</B>()
|
|
|
|
is specified in POSIX.1-2008.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Filename entries can be read from a directory stream using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3).
|
|
|
|
<P>
|
|
|
|
The underlying file descriptor of the directory stream can be obtained using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+dirfd">dirfd</A></B>(3).
|
|
|
|
<P>
|
|
|
|
The
|
|
<B>opendir</B>()
|
|
|
|
function sets the close-on-exec flag for the file descriptor underlying the
|
|
<I>DIR *</I>.
|
|
|
|
The
|
|
<B>fdopendir</B>()
|
|
|
|
function leaves the setting of the close-on-exec
|
|
flag unchanged for the file descriptor,
|
|
<I>fd</I>.
|
|
|
|
POSIX.1-200x leaves it unspecified whether a successful call to
|
|
<B>fdopendir</B>()
|
|
|
|
will set the close-on-exec flag for the file descriptor,
|
|
<I>fd</I>.
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+open">open</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+closedir">closedir</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+dirfd">dirfd</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+rewinddir">rewinddir</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+scandir">scandir</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+seekdir">seekdir</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+telldir">telldir</A></B>(3)
|
|
|
|
<A NAME="lbAL"> </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"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="12"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="13"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="14"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="15"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="16"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="17"><A HREF="#lbAH">ATTRIBUTES</A><DD>
|
|
<DT id="18"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="19"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DT id="20"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="21"><A HREF="#lbAL">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:49 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|