Data structure for a directory entry
#include <dirent.h>
struct dirent {
#if __OFF_BITS__ == 64
ino_t d_ino;
off_t d_offset;
#elif __OFF_BITS__ == 32
# if defined(__LITTLEENDIAN__)
ino_t d_ino;
ino_t d_ino_hi;
off_t d_offset;
off_t d_offset_hi;
# elif defined(__BIGENDIAN__)
ino_t d_ino_hi;
ino_t d_ino;
off_t d_offset_hi;
off_t d_offset;
# else
# error endian not configured for system
# endif
#else
# error __OFF_BITS__ value is unsupported
#endif
int16_t d_reclen;
int16_t d_namelen;
__FLEXARY(char, d_name); /* char d_name[] */
};
#ifdef __EXT_LF64SRC
struct dirent64 {
ino64_t d_ino;
off64_t d_offset;
int16_t d_reclen;
int16_t d_namelen;
__FLEXARY(char, d_name); /* char d_name[] */
};
#endif
The dirent structure describes an entry in a directory. The dirent64 structure is for large-file support.
The members include:
struct dirent *entry; entry = malloc( offsetof(struct dirent, d_name) + NAME_MAX + 1 );
or:
struct {
struct dirent ent;
char namebuf[NAME_MAX + 1 + offsetof(struct dirent, d_name) -
sizeof( struct dirent)];
} entry
dirent is POSIX 1003.1; dirent64 is Large-file support