2 .\" Copyright (C) 2008, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" and Copyright (C) 2016 Florian Weimer <fweimer@redhat.com>
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
7 .TH readdir_r 3 (date) "Linux man-pages (unreleased)"
9 readdir_r \- read a directory
12 .RI ( libc ", " \-lc )
15 .B #include <dirent.h>
17 .BI "[[deprecated]] int readdir_r(DIR *restrict " dirp ,
18 .BI " struct dirent *restrict " entry ,
19 .BI " struct dirent **restrict " result );
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
30 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
33 This function is deprecated; use
39 function was invented as a reentrant version of
41 It reads the next directory entry from the directory stream
43 and returns it in the caller-allocated buffer pointed to by
50 A pointer to the returned buffer is placed in
52 if the end of the directory stream was encountered,
53 then NULL is instead returned in
56 It is recommended that applications use
60 Furthermore, since glibc 2.24, glibc deprecates
62 The reasons are as follows:
68 may be unsafe because the interface does not allow the caller to specify
69 the length of the buffer used for the returned directory entry.
73 can't read directory entries with very long names.
74 When the glibc implementation encounters such a name,
78 .IR "after the final directory entry has been read" .
79 On some other systems,
81 may return a success status, but the returned
83 field may not be null terminated or may be truncated.
85 In the current POSIX.1 specification (POSIX.1-2008),
87 is not required to be thread-safe.
88 However, in modern implementations (including the glibc implementation),
91 that specify different directory streams are thread-safe.
94 is generally unnecessary in multithreaded programs.
95 In cases where multiple threads must read from the same directory stream,
98 with external synchronization is still preferable to the use of
100 for the reasons given in the points above.
102 It is expected that a future version of POSIX.1
104 .\" http://www.austingroupbugs.net/view.php?id=696
107 obsolete, and require that
109 be thread-safe when concurrently employed on different directory streams.
113 function returns 0 on success.
114 On error, it returns a positive error number (listed under ERRORS).
115 If the end of the directory stream is reached,
117 returns 0, and returns NULL in
122 Invalid directory stream descriptor \fIdirp\fP.
125 A directory entry whose name was too long to be read was encountered.
127 For an explanation of the terms used in this section, see
135 Interface Attribute Value
138 T} Thread safety MT-Safe