dirent.h File

The _DNAME_MAX and PATH_MAX constants specify maximum file names and path names, respectively, across all types of file systems. The constants defined by a particular file system are applicable only to that file system. Using file system-specific constants and directory structures makes it very difficult to port code across different types of file systems.

Purpose

Describes the format of a file system-independent directory entry.

Description

The /usr/include/dirent.h file describes the format of a directory entry without reference to the type of underlying system.

The dirent structure, defined in the dirent.h file, is used for directory access operations. Using these access operations and the dirent structure, along with its associated constants and macros, shields you from the details of implementing a directory and provides a consistent interface to directories across all types of file systems.

The dirent structure contains the following fields for each directory entry:

ulong_t d_offset;                /* actual offset of this entry */
ino_t           d_ino;           /* inode number of entry */
ushort_t        d_reclen;        /* length of this entry */
ushort_t        d_namlen;        /* length of string in d_name */
char d_name[_D_NAME_MAX+1];      /* name of entry (filename) */

_D_NAME_MAX is a constant that indicates the maximum number of bytes in a file name for all file systems. (Related to this constant is the PATH_MAX constant, which specifies the maximum number of bytes in the full path name of a file, not including the terminating null byte.)

The value of the _D_NAME_MAX constant is specific to each type of filesystem type. It can be determined by using the pathconf or fpathconf subroutine.

The size of a dirent structure depends on the number of bytes in the file name.