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

198 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of READDIR</TITLE>
</HEAD><BODY>
<H1>READDIR</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<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>
readdir - read directory entry
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>int readdir(unsigned int </B><I>fd</I><B>, struct old_linux_dirent *</B><I>dirp</I><B>,</B>
<B> unsigned int </B><I>count</I><B>);</B>
</PRE>
<P>
<I>Note</I>:
There is no glibc wrapper for this system call; see NOTES.
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This is not the function you are interested in.
Look at
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
for the POSIX conforming C library interface.
This page documents the bare kernel system call interface,
which is superseded by
<B><A HREF="/cgi-bin/man/man2html?2+getdents">getdents</A></B>(2).
<P>
<B>readdir</B>()
reads one
<I>old_linux_dirent</I>
structure from the directory
referred to by the file descriptor
<I>fd</I>
into the buffer pointed to by
<I>dirp</I>.
The argument
<I>count</I>
is ignored; at most one
<I>old_linux_dirent</I>
structure is read.
<P>
The
<I>old_linux_dirent</I>
structure is declared (privately in Linux kernel file
<B>fs/readdir.c</B>)
as follows:
<P>
struct old_linux_dirent {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;d_ino;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;inode&nbsp;number&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;long&nbsp;d_offset;&nbsp;&nbsp;/*&nbsp;offset&nbsp;to&nbsp;this&nbsp;<I>old_linux_dirent</I>&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;unsigned&nbsp;short&nbsp;d_namlen;&nbsp;/*&nbsp;length&nbsp;of&nbsp;this&nbsp;<I>d_name</I>&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;&nbsp;d_name[1];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;filename&nbsp;(null-terminated)&nbsp;*/
}
<P>
<I>d_ino</I>
is an inode number.
<I>d_offset</I>
is the distance from the start of the directory to this
<I>old_linux_dirent</I>.
<I>d_reclen</I>
is the size of
<I>d_name</I>,
not counting the terminating null byte ('\0').
<I>d_name</I>
is a null-terminated filename.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, 1 is returned.
On end of directory, 0 is returned.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EBADF</B>
<DD>
Invalid file descriptor
<I>fd</I>.
<DT id="2"><B>EFAULT</B>
<DD>
Argument points outside the calling process's address space.
<DT id="3"><B>EINVAL</B>
<DD>
Result buffer is too small.
<DT id="4"><B>ENOENT</B>
<DD>
No such directory.
<DT id="5"><B>ENOTDIR</B>
<DD>
File descriptor does not refer to a directory.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
This system call is Linux-specific.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
Glibc does not provide a wrapper for this system call; call it using
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
You will need to define the
<I>old_linux_dirent</I>
structure yourself.
However, probably you should use
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
instead.
<P>
This system call does not exist on x86-64.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+getdents">getdents</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+readdir">readdir</A></B>(3)
<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="6"><A HREF="#lbAB">NAME</A><DD>
<DT id="7"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="8"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="9"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="10"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="11"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="12"><A HREF="#lbAH">NOTES</A><DD>
<DT id="13"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="14"><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:34 GMT, March 31, 2021
</BODY>
</HTML>