Read a directory (reentrant)
#include <sys/types.h> #include <dirent.h> int readdir_r( DIR * dirp, struct dirent * entry, struct dirent ** result );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The readdir_r() function initializes the dirent structure referenced by entry with the directory entry at the current position in the directory stream referred to by dirp, and stores a pointer to this structure in result.
The storage pointed to by entry must be large enough for a dirent structure with the d_name member an array of char containing at least NAME_MAX plus one element.
|The struct dirent structure doesn't include space
for the pathname; you must provide it.
struct dirent *entry; entry = malloc( offsetof(struct dirent, d_name) + NAME_MAX + 1 );
Some filesystems support names that are longer than the value of NAME_MAX. You can use pathconf() with _PC_NAME_MAX to determine the maximum number of bytes (not including the terminating null) allowed in a file name for a particular filesystem.
POSIX 1003.1 TSF
closedir(), dirent, errno, opendir(), readdir(), seekdir(), telldir(), rewinddir()