Get a directory entry.
Syntax
#include <dirent.h>
struct dirent *readdir (DIR *d);
Parameters
-
d
The directory structure returned by
opendir
.
Return Value
The return value is a pointer to a dirent
structure if successful. Otherwise,
the return value is null and errno is set:
-
ENOMEM
Out of memory.
-
ENOTDIR
Not a directory. May happen on internal API error (unintentional file descriptor reuse).
-
ENOSYS
System call not implemented. May happen on internal API error (unintentional file descriptor reuse).
-
EBADF
Bad file descriptor.
The returned dirent
structure contains the following entries:
ino_t d_ino;
char d_name[64];
The d_ino
field is currently unused.
Remarks
The returned dirent
structure is globally allocated in order to not rely on
malloc
and free
. This implies that the implementation is not thread safe,
and it is not possible to access more than one directory at the same time from
within the same process.
The memory associated with the returned dirent
structure is handled by the
API and must not be freed. It is reused with each call to readdir
, and freed
with the DIR
structure when the directory is closed using closedir
.