Reads the directory entries of a directory.
(IN/OUT) Specifies the structure to receive information about the next directory entry. See DIR.
If successful, returns a pointer to a DIR object structure containing information about the next directory entry. When the end of the directory is encountered, NULL is returned and errno is not changed.
If an error occurs, NULL is returned and errno is set to indicate one of the following errors.
The readdir function can be called repeatedly to obtain the list of file and directory names contained in the directory specified by the pathname given to the opendir function.
The closedir function must be called to close the directory and free the memory allocated by the opendir function.
The readdir function does not return entries containing empty names. If entries for dot or dot-dot exist, one entry is returned for dot and one entry is returned for dot-dot; otherwise, they are not returned.
The pointer returned by readdir points to data, which may be overwritten 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 or added to the directory after the most recent call to opendir or rewinddir, a subsequent call to readdir might or might not return an entry for the file; the behavior is unspecified.
The readdir function marks for update the st_atime field of the directory each time the directory is actually read.