236 lines
5.6 KiB
HTML
236 lines
5.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of READDIR_R</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>READDIR_R</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2016-03-01<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>
|
|
|
|
readdir_r - read a directory
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/dirent.h">dirent.h</A>></B>
|
|
|
|
<B>int readdir_r(DIR *</B><I>dirp</I><B>, struct dirent *</B><I>entry</I><B>, struct dirent **</B><I>result</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>readdir_r</B>():
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
_POSIX_C_SOURCE
|
|
<BR> || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
This function is deprecated; use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
instead.
|
|
<P>
|
|
|
|
The
|
|
<B>readdir_r</B>()
|
|
|
|
function was invented as a reentrant version of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3).
|
|
|
|
It reads the next directory entry from the directory stream
|
|
<I>dirp</I>,
|
|
|
|
and returns it in the caller-allocated buffer pointed to by
|
|
<I>entry</I>.
|
|
|
|
For details of the
|
|
<I>dirent</I>
|
|
|
|
structure, see
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3).
|
|
|
|
<P>
|
|
|
|
A pointer to the returned buffer is placed in
|
|
<I>*result</I>;
|
|
|
|
if the end of the directory stream was encountered,
|
|
then NULL is instead returned in
|
|
<I>*result</I>.
|
|
|
|
<P>
|
|
|
|
It is recommended that applications use
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
instead of
|
|
<B>readdir_r</B>().
|
|
|
|
Furthermore, since version 2.24, glibc deprecates
|
|
<B>readdir_r</B>().
|
|
|
|
The reasons are as follows:
|
|
<DL COMPACT>
|
|
<DT id="2">*<DD>
|
|
On systems where
|
|
<B>NAME_MAX</B>
|
|
|
|
is undefined, calling
|
|
<B>readdir_r</B>()
|
|
|
|
may be unsafe because the interface does not allow the caller to specify
|
|
the length of the buffer used for the returned directory entry.
|
|
<DT id="3">*<DD>
|
|
On some systems,
|
|
<B>readdir_r</B>()
|
|
|
|
can't read directory entries with very long names.
|
|
When the glibc implementation encounters such a name,
|
|
<B>readdir_r</B>()
|
|
|
|
fails with the error
|
|
<B>ENAMETOOLONG</B>
|
|
|
|
<I>after the final directory entry has been read</I>.
|
|
|
|
On some other systems,
|
|
<B>readdir_r</B>()
|
|
|
|
may return a success status, but the returned
|
|
<I>d_name</I>
|
|
|
|
field may not be null terminated or may be truncated.
|
|
<DT id="4">*<DD>
|
|
In the current POSIX.1 specification (POSIX.1-2008),
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
is not required to be thread-safe.
|
|
However, in modern implementations (including the glibc implementation),
|
|
concurrent calls to
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
that specify different directory streams are thread-safe.
|
|
Therefore, the use of
|
|
<B>readdir_r</B>()
|
|
|
|
is generally unnecessary in multithreaded programs.
|
|
In cases where multiple threads must read from the same directory stream,
|
|
using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
with external synchronization is still preferable to the use of
|
|
<B>readdir_r</B>(),
|
|
|
|
for the reasons given in the points above.
|
|
<DT id="5">*<DD>
|
|
It is expected that a future version of POSIX.1
|
|
|
|
|
|
will make
|
|
<B>readdir_r</B>()
|
|
|
|
obsolete, and require that
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
be thread-safe when concurrently employed on different directory streams.
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The
|
|
<B>readdir_r</B>()
|
|
|
|
function returns 0 on success.
|
|
On error, it returns a positive error number (listed under ERRORS).
|
|
If the end of the directory stream is reached,
|
|
<B>readdir_r</B>()
|
|
|
|
returns 0, and returns NULL in
|
|
<I>*result</I>.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="6"><B>EBADF</B>
|
|
|
|
<DD>
|
|
Invalid directory stream descriptor <I>dirp</I>.
|
|
<DT id="7"><B>ENAMETOOLONG</B>
|
|
|
|
<DD>
|
|
A directory entry whose name was too long to be read was encountered.
|
|
</DL>
|
|
<A NAME="lbAG"> </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>readdir_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
|
|
|
|
<A NAME="lbAJ"> </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="8"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="9"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="10"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="11"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="12"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="13"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="14"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="15"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="16"><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:54 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|