Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

readdir_r - read directory (thread-safe)

&pagelevel(4)&pagelevel

Syntax

#include <sys/types.h>

#include <dirent.h>

int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); 

Description

The function readdir_r() is the thread-safe version of the function readdir().

The function readdir_r() initializes the dirent structure pointed to by entry with the next
non-empty directory entry in the directory stream pointed to by dirp, stores a pointer to this
structure at the location pointed to by result and positions the directory stream to point to the
next entry.

The storage area pointed to by entry must be large enough to store {NAME_MAX} plus one
character for the char array d_name from the dirent structure in the worst-case scenario.

If it returns successfully, the pointer returned for *result has the same value as the entry
argument. If the end of the directory stream has been reached, this pointer contains the
value NULL.

The function readdir_r() does not return any directory entries that contain empty names.

readdir_r() can temporarily store several directory entries for a single read operation;
readdir_r() updates the st_atime structure component of the directory every time the
directory is actually read.

Return val.

0

Error number

if successful.

otherwise, to indicate an error. errno is set to indicate the error.

Errors

The function readdir_r() fails if:

EBADF              The dirp argument does not point to an open directory stream.

See also

readdir(), dirent(), types().