Operating systems, development tools, and professional services
for connected embedded systems
for connected embedded systems
![]() |
![]() |
![]() |
![]() |
dirent
Data structure for a directory entry
Synopsis:
#include <dirent.h>
struct dirent {
#if _FILE_OFFSET_BITS - 0 == 64
ino_t d_ino; /* File serial number. */
off_t d_offset;
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
#if defined(__LITTLEENDIAN__)
ino_t d_ino; /* File serial number. */
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; /* File serial number. */
off_t d_offset_hi;
off_t d_offset;
#else
#error endian not configured for system
#endif
#else
#error _FILE_OFFSET_BITS value is unsupported
#endif
_Int16t d_reclen;
_Int16t d_namelen;
char d_name[1];
};
Description:
The dirent structure describes an entry in a directory. 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
- Typically used to identify the directory entry itself. 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.
![]() |
The struct dirent structure doesn't include space
for the pathname.
If you create an instance of this structure, you must provide space for
the name:
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:
See also:
readdir(), readdir_r(), scandir()
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)
