// INCLUDE #include <dirent.h> // PROTOTYPE int readdir_r(DIR* pdir, struct dirent* dentry, struct dirent** out_dirent)
Reads the next entry from a directory. Used to find the names of all of the files and directories within a directory. See also
dentry: Pass in a pointer to a
struct direntto be filled in with the current directory entry.
out_dirent: If not
NULL, filled in with
dentryif a directory entry was retrieved, or
NULLif at the end of the directory.
Not all fields of
dentry are filled in. You should only rely on:
d_type: Type of entry:
d_name: Name of the file or directory. Just the name, not the whole path.
Returns 0 on success. On error, returns -1 and sets