readdir
raw OCR
Reads the current entry from a directory stream.
Defined in header <dirent.h>
Syntax
#include <dirent.h>
struct dirent readdir(DIR *dirp);
readdir is available on POSlX-compliant UNIX systems.
The readdir function reads the current directory entry in the directory
stream pointed to by dirp. The directory stream is advanced to the next
entry.
The readdir function returns a pointer to a dirent structure that is
overwritten by each call to the function on the same directory stream. The
structure is not overwritten by a readdir call on a different directory
stream.
The dirent structure corresponds to a single directory entry. It is defined
in dirent.h, and contains (in addition to other non-accessible members) the
following member:
char d_name[];
where d_name is an array of characters containing the null terminated file
name for the current directory entry. The size of the array is
indeterminate; use strlen to determine the length of the filename.
All valid directory entries are returned, including subdirectories, "." and
".." entries, system files,hidden files, and volume labels. Unused or
deleted directory entries are skipped.
A directory entry can be created or deleted while a directory stream is
being read, but readdir may or may not return the affected directory
entry. Rewinding the directory with rewinddir or reopening it with
opendir will ensure that readdir will reflect the current stateof the
directory.
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Return value
If successful, readdir returns a pointer to the current directory entry for the directory stream. If the end of the directory has been reached, or dirp does not refer to an open directory stream, readdir returns NULL.
See also
Example
See the example for opendir.
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/dirent.h/readdir/
· short form /3.1/readdir/