1READDIR(3) Linux Programmer's Manual READDIR(3)
2
3
4
6 readdir - read a directory
7
9 #include <sys/types.h>
10
11 #include <dirent.h>
12
13 struct dirent *readdir(DIR *dir);
14
16 The readdir() function returns a pointer to a dirent structure repre‐
17 senting the next directory entry in the directory stream pointed to by
18 dir. It returns NULL on reaching the end-of-file or if an error
19 occurred.
20
21 On Linux, the dirent structure is defined as follows:
22
23 struct dirent {
24 ino_t d_ino; /* inode number */
25 off_t d_off; /* offset to the next dirent */
26 unsigned short d_reclen; /* length of this record */
27 unsigned char d_type; /* type of file */
28 char d_name[256]; /* filename */
29 };
30
31 According to POSIX, the dirent structure contains a field char d_name[]
32 of unspecified size, with at most NAME_MAX characters preceding the
33 terminating null byte. POSIX.1-2001 also documents the field ino_t
34 d_ino as an XSI extension. Use of other fields will harm the portabil‐
35 ity of your programs.
36
37 The data returned by readdir() may be overwritten by subsequent calls
38 to readdir() for the same directory stream.
39
41 The readdir() function returns a pointer to a dirent structure, or NULL
42 if an error occurs or end-of-file is reached. On error, errno is set
43 appropriately.
44
46 EBADF Invalid directory stream descriptor dir.
47
49 SVr4, 4.3BSD, POSIX.1-2001
50
52 read(2), closedir(3), dirfd(3), ftw(3), opendir(3), rewinddir(3), scan‐
53 dir(3), seekdir(3), telldir(3)
54
55
56
57 1996-04-22 READDIR(3)