readdir_r(), readdir64_r()
Read a directory (reentrant)
Synopsis:
#include <sys/types.h>
#include <dirent.h>
int readdir_r( DIR *dirp,
struct dirent *entry,
struct dirent **result );
int readdir64_r( DIR *dirp,
struct dirent64 *dirent,
struct dirent64 **result );
Arguments:
- dirp
- A pointer to the directory stream to be read.
- entry
- A pointer to a dirent or dirent64 structure where the function can store the directory entry.
- result
- The address of a location where the function can store a pointer to the information found.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The readdir_r() and readdir64_r() functions initialize the dirent structure referenced by entry with the directory entry at the current position in the directory stream referred to by dirp, store a pointer to this structure in *result, and position the directory stream at the next entry. If you've reached the end of the directory stream, these functions set *result to NULL. The readdir64_r() function is a large-file support version of readdir_r().
Classificationin What's in a Function Description?
The storage pointed to by entry must be large enough for a dirent or dirent64 structure with the d_name member an array of char containing at least NAME_MAX + 1 elements. The struct dirent and struct dirent64 structures don't include space for the pathname; you must provide it. For example:
struct dirent *entry;
entry = malloc( offsetof(struct dirent, d_name) + NAME_MAX + 1 );
Returns:
- EOK
- Success.
- EOVERFLOW
- One of the values in the structure to be returned can't be represented correctly.
Classification:
readdir_r() is POSIX 1003.1; readdir64_r() is Large-file support
Safety: | |
---|---|
Cancellation point | Yes |
Signal handler | No |
Thread | Yes |