#include <dirent.h>
The <dirent.h> header shall define the following type:
It shall also define the structure dirent which shall include the following members:
ino_t d_ino File serial number. char d_name[] Filename string of entry.
The <dirent.h> header shall define the ino_t type as described in <sys/types.h>.
The array d_name is of unspecified size, but shall contain a filename of at most {NAME_MAX} bytes followed by a terminating null byte.
The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.
int alphasort(const struct dirent **, const struct dirent **); int closedir(DIR *); int dirfd(DIR *); DIR *fdopendir(int); DIR *opendir(const char *); struct dirent *readdir(DIR *); int readdir_r(DIR *restrict, struct dirent *restrict, struct dirent **restrict); void rewinddir(DIR *); int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); void seekdir(DIR *, long); long telldir(DIR *);
The following sections are informative.
The name of an array of char of an unspecified size should not be used as an lvalue. Use of:
sizeof(d_name)
is incorrect; use:
strlen(d_name)
instead.
The array of char d_name is not a fixed size. Implementations may need to declare struct dirent with an array size for d_name of 1, but the actual number of bytes provided matches (or only slightly exceeds) the length of the filename string.
The System Interfaces volume of POSIX.1-2017, alphasort(), closedir(), dirfd(), fdopendir(), readdir(), rewinddir(), seekdir(), telldir()
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .