The data type DIR , which is defined in the header dirent.h , represents a directory stream, which is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files; files may be removed from a directory or added to a directory asynchronously to the operation of readdir() . readdir() returns a pointer to a structure containing the next non-empty directory entry in the directory stream to which dirp points, and positions the directory stream at the next entry. It returns a null pointer upon reaching the end of the directory stream. The directory entry is described by the structure dirent (see dirent.h ).
readdir() does not return directory entries containing empty names. If entries for dot (current directory) or dot-dot (parent directory) exist, one entry is returned for dot, and only one entry is returned for dot-dot.
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 was removed from or added to the directory after the most recent call to opendir() or rewinddir() , it is undefined whether a subsequent call to readdir() will return an entry for that file. readdir() can buffer multiple directory entries in a single read operation; it updates the st_atime structure component of the directory each time the directory is actually read (see also sys/stat.h ).
After a call to fork() , either the parent or child (but not both) may continue processing the directory stream by using readdir() , rewind() or seekdir() . If both the parent and child processes use these functions, the result is undefined. There is no difference in functionality between readdir() and readdir64() except that readdir64() uses a dirent64 structure. The dirent64 structure corresponds to the dirent structure except for the following components: ino64_t d_ino
readdir() and readdir64() are not thread-safe. Use the reentrant function readdir_r() instead of readdir() if needed. There is currently no reentrant version of the readdir64() function.
|