Finds entries in a directory.
#include <dirent.h> struct dirent *readdir (DIR *dir_pointer);
The type DIR defined in the <dirent.h> header file represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove from or add files to a directory asynchronously to the operation of the readdir function.
The pointer returned by the readdir function points to data that you can overwrite by another call to readdir on the same directory stream. This data is not overwritten by another call to readdir on a different directory stream.
If a file is removed from or added to the directory after the most recent call to the opendir or rewinddir function, whether a subsequent call to the readdir function returns an entry for that file, is unspecified.
When it reaches the end of the directory, or when it detects an invalid seekdir operation, the readdir function returns the null value.
An attempt to seek to an invalid location causes the readdir function to return the null value the next time it is called. A previous telldir function call returns the position.
See also opendir, rewinddir, seekdir, and telldir in this section.
See the description of closedir for an example.
x | A pointer to an object of type struct dirent. |
NULL | Indicates an error, returns a pointer. The global errno indicates the error. When the end of the directory is encountered, errno is not changed. |