dirent, dirent64

Data structure for a directory entry

Synopsis:

#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

Description:

The dirent structure describes an entry in a directory. The dirent64 structure is for large-file support.

Note: In QNX Neutrino 6.6 or later, the large-file support functions and data types appear in the name space only if you define _LARGEFILE64_SOURCE when you compile your code. For more information, see "Classification" in What's in a Function Description?

The members include:

d_ino
A mountpoint-unique file serial number. This serial number is often used in various disk-checking utilities for such operations as determining infinite-loop directory links. (Note that the inode value cannot be zero, which would indicate that the inode represents an unused entry.)
d_offset
In some filesystems, this member identifies the directory entry itself; in others, it's the offset of the next directory entry. For a disk-based filesystem, this value might be the actual offset into the on-disk directory structure.
d_reclen
The size of this directory entry and any other associated information (such as an optional struct stat structure appended to the struct dirent entry).
d_namelen
The size of the d_name member. Since the size is calculated using strlen(), the \0 string terminator, which must be present, isn't counted.
d_name
The actual name of that directory entry.
Note: These structures include space only for the first four bytes of the pathname. If you create an instance of this structure, you must provide space for the name, including the terminating null character:
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

Classification:

dirent is POSIX 1003.1; dirent64 is Large-file support