1dirent.h(0P)               POSIX Programmer's Manual              dirent.h(0P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       dirent.h — format of directory entries
13

SYNOPSIS

15       #include <dirent.h>
16

DESCRIPTION

18       The internal format of directories is unspecified.
19
20       The <dirent.h> header shall define the following type:
21
22       DIR     A type representing a directory stream. The DIR type may be  an
23               incomplete type.
24
25       It  shall also define the structure dirent which shall include the fol‐
26       lowing members:
27
28
29           ino_t  d_ino       File serial number.
30           char   d_name[]    Filename string of entry.
31
32       The <dirent.h> header shall define  the  ino_t  type  as  described  in
33       <sys/types.h>.
34
35       The  array  d_name is of unspecified size, but shall contain a filename
36       of at most {NAME_MAX} bytes followed by a terminating null byte.
37
38       The following shall be declared as functions and may also be defined as
39       macros. Function prototypes shall be provided.
40
41
42           int            alphasort(const struct dirent **, const struct dirent **);
43           int            closedir(DIR *);
44           int            dirfd(DIR *);
45           DIR           *fdopendir(int);
46           DIR           *opendir(const char *);
47           struct dirent *readdir(DIR *);
48           int            readdir_r(DIR *restrict, struct dirent *restrict,
49                              struct dirent **restrict);
50           void           rewinddir(DIR *);
51           int            scandir(const char *, struct dirent ***,
52                              int (*)(const struct dirent *),
53                              int (*)(const struct dirent **,
54                              const struct dirent **));
55           void           seekdir(DIR *, long);
56           long           telldir(DIR *);
57
58       The following sections are informative.
59

APPLICATION USAGE

61       None.
62

RATIONALE

64       Information  similar to that in the <dirent.h> header is contained in a
65       file <sys/dir.h> in 4.2 BSD and 4.3 BSD. The equivalent in these imple‐
66       mentations  of struct dirent from this volume of POSIX.1‐2017 is struct
67       direct.  The filename was changed because the name <sys/dir.h> was also
68       used  in earlier implementations to refer to definitions related to the
69       older access method; this produced name  conflicts.  The  name  of  the
70       structure was changed because this volume of POSIX.1‐2017 does not com‐
71       pletely define what is in the structure, so it could  be  different  on
72       some implementations from struct direct.
73
74       The  name of an array of char of an unspecified size should not be used
75       as an lvalue. Use of:
76
77
78           sizeof(d_name)
79
80       is incorrect; use:
81
82
83           strlen(d_name)
84
85       instead.
86
87       The array of char d_name is not a fixed size. Implementations may  need
88       to  declare  struct  dirent with an array size for d_name of 1, but the
89       actual number of bytes provided matches (or only slightly exceeds)  the
90       length of the filename string.
91

FUTURE DIRECTIONS

93       None.
94

SEE ALSO

96       <sys_types.h>
97
98       The  System Interfaces volume of POSIX.1‐2017, alphasort(), closedir(),
99       dirfd(), fdopendir(), readdir(), rewinddir(), seekdir(), telldir()
100
102       Portions of this text are reprinted and reproduced in  electronic  form
103       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
104       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
105       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
106       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
107       event of any discrepancy between this version and the original IEEE and
108       The Open Group Standard, the original IEEE and The Open Group  Standard
109       is  the  referee document. The original Standard can be obtained online
110       at http://www.opengroup.org/unix/online.html .
111
112       Any typographical or formatting errors that appear  in  this  page  are
113       most likely to have been introduced during the conversion of the source
114       files to man page format. To report such errors,  see  https://www.ker
115       nel.org/doc/man-pages/reporting_bugs.html .
116
117
118
119IEEE/The Open Group                  2017                         dirent.h(0P)
Impressum