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 2016-03-01 "" "Linux Programmer's Manual"
28 readdir_r \- read a directory
31 .B #include <dirent.h>
33 .BI "int readdir_r(DIR *" dirp ", struct dirent *" entry \
34 ", struct dirent **" result );
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
46 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
50 This function is deprecated; use
56 function was invented as a reentrant version of
58 It reads the next directory entry from the directory stream
60 and returns it in the caller-allocated buffer pointed to by
67 A pointer to the returned buffer is placed in
69 if the end of the directory stream was encountered,
70 then NULL is instead returned in
73 It is recommended that applications use
77 Furthermore, since version 2.24, glibc deprecates
79 The reasons are as follows:
85 may be unsafe because the interface does not allow the caller to specify
86 the length of the buffer used for the returned directory entry.
90 can't read directory entries with very long names.
91 When the glibc implementation encounters such a name,
95 .IR "after the final directory entry has been read" .
96 On some other systems,
98 may return a success status, but the returned
100 field may not be null terminated or may be truncated.
102 In the current POSIX.1 specification (POSIX.1-2008),
104 is not required to be thread-safe.
105 However, in modern implementations (including the glibc implementation),
108 that specify different directory streams are thread-safe.
109 Therefore, the use of
111 is generally unnecessary in multithreaded programs.
112 In cases where multiple threads must read from the same directory stream,
115 with external synchronization is still preferable to the use of
117 for the reasons given in the points above.
119 It is expected that a future version of POSIX.1
121 .\" http://www.austingroupbugs.net/view.php?id=696
124 obsolete, and require that
126 be thread-safe when concurrently employed on different directory streams.
130 function returns 0 on success.
131 On error, it returns a positive error number (listed under ERRORS).
132 If the end of the directory stream is reached,
134 returns 0, and returns NULL in
139 Invalid directory stream descriptor \fIdirp\fP.
142 A directory entry whose name was too long to be read was encountered.
144 For an explanation of the terms used in this section, see
150 Interface Attribute Value
153 T} Thread safety MT-Safe
156 POSIX.1-2001, POSIX.1-2008.