1 .\" Copyright (C) 2008, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\" and Copyright (C) 2016 Florian Weimer <fweimer@redhat.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .TH READDIR_R 3 2021-03-22 "" "Linux Programmer's Manual"
28 readdir_r \- read a directory
31 .B #include <dirent.h>
33 .BI "int readdir_r(DIR *restrict " dirp ", struct dirent *restrict " entry ,
34 .BI " struct dirent **restrict " result );
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
45 || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
48 This function is deprecated; use
54 function was invented as a reentrant version of
56 It reads the next directory entry from the directory stream
58 and returns it in the caller-allocated buffer pointed to by
65 A pointer to the returned buffer is placed in
67 if the end of the directory stream was encountered,
68 then NULL is instead returned in
71 It is recommended that applications use
75 Furthermore, since version 2.24, glibc deprecates
77 The reasons are as follows:
83 may be unsafe because the interface does not allow the caller to specify
84 the length of the buffer used for the returned directory entry.
88 can't read directory entries with very long names.
89 When the glibc implementation encounters such a name,
93 .IR "after the final directory entry has been read" .
94 On some other systems,
96 may return a success status, but the returned
98 field may not be null terminated or may be truncated.
100 In the current POSIX.1 specification (POSIX.1-2008),
102 is not required to be thread-safe.
103 However, in modern implementations (including the glibc implementation),
106 that specify different directory streams are thread-safe.
107 Therefore, the use of
109 is generally unnecessary in multithreaded programs.
110 In cases where multiple threads must read from the same directory stream,
113 with external synchronization is still preferable to the use of
115 for the reasons given in the points above.
117 It is expected that a future version of POSIX.1
119 .\" http://www.austingroupbugs.net/view.php?id=696
122 obsolete, and require that
124 be thread-safe when concurrently employed on different directory streams.
128 function returns 0 on success.
129 On error, it returns a positive error number (listed under ERRORS).
130 If the end of the directory stream is reached,
132 returns 0, and returns NULL in
137 Invalid directory stream descriptor \fIdirp\fP.
140 A directory entry whose name was too long to be read was encountered.
142 For an explanation of the terms used in this section, see
150 Interface Attribute Value
153 T} Thread safety MT-Safe
159 POSIX.1-2001, POSIX.1-2008.