1READDIR_R(3)               Linux Programmer's Manual              READDIR_R(3)
2
3
4

NAME

6       readdir_r - read a directory
7

SYNOPSIS

9       #include <dirent.h>
10
11       int readdir_r(DIR *restrict dirp, struct dirent *restrict entry,
12                     struct dirent **restrict result);
13
14   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16       readdir_r():
17           _POSIX_C_SOURCE
18               || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
19

DESCRIPTION

21       This function is deprecated; use readdir(3) instead.
22
23       The  readdir_r()  function was invented as a reentrant version of read‐
24       dir(3).  It reads the next directory entry from  the  directory  stream
25       dirp,  and  returns it in the caller-allocated buffer pointed to by en‐
26       try.  For details of the dirent structure, see readdir(3).
27
28       A pointer to the returned buffer is placed in *result; if  the  end  of
29       the  directory stream was encountered, then NULL is instead returned in
30       *result.
31
32       It is recommended that applications use  readdir(3)  instead  of  read‐
33       dir_r().   Furthermore,  since  version  2.24,  glibc  deprecates read‐
34       dir_r().  The reasons are as follows:
35
36       *  On systems where NAME_MAX is undefined, calling readdir_r()  may  be
37          unsafe  because  the  interface does not allow the caller to specify
38          the length of the buffer used for the returned directory entry.
39
40       *  On some systems, readdir_r() can't read directory entries with  very
41          long  names.   When the glibc implementation encounters such a name,
42          readdir_r() fails with the error ENAMETOOLONG after the final direc‐
43          tory  entry  has  been read.  On some other systems, readdir_r() may
44          return a success status, but the returned d_name field  may  not  be
45          null terminated or may be truncated.
46
47       *  In  the  current POSIX.1 specification (POSIX.1-2008), readdir(3) is
48          not required to be thread-safe.  However, in modern  implementations
49          (including the glibc implementation), concurrent calls to readdir(3)
50          that specify different directory streams  are  thread-safe.   There‐
51          fore,  the  use  of  readdir_r()  is generally unnecessary in multi‐
52          threaded programs.  In cases where multiple threads must  read  from
53          the  same  directory stream, using readdir(3) with external synchro‐
54          nization is still preferable to the use of readdir_r(), for the rea‐
55          sons given in the points above.
56
57       *  It  is  expected  that  a  future version of POSIX.1 will make read‐
58          dir_r() obsolete, and require that readdir(3)  be  thread-safe  when
59          concurrently employed on different directory streams.
60

RETURN VALUE

62       The  readdir_r() function returns 0 on success.  On error, it returns a
63       positive error number (listed under ERRORS).  If the end of the  direc‐
64       tory stream is reached, readdir_r() returns 0, and returns NULL in *re‐
65       sult.
66

ERRORS

68       EBADF  Invalid directory stream descriptor dirp.
69
70       ENAMETOOLONG
71              A directory entry whose name was too long to be read was encoun‐
72              tered.
73

ATTRIBUTES

75       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
76       tributes(7).
77
78       ┌────────────────────────────────────────────┬───────────────┬─────────┐
79Interface                                   Attribute     Value   
80       ├────────────────────────────────────────────┼───────────────┼─────────┤
81readdir_r()                                 │ Thread safety │ MT-Safe │
82       └────────────────────────────────────────────┴───────────────┴─────────┘
83

CONFORMING TO

85       POSIX.1-2001, POSIX.1-2008.
86

SEE ALSO

88       readdir(3)
89

COLOPHON

91       This page is part of release 5.13 of the Linux  man-pages  project.   A
92       description  of  the project, information about reporting bugs, and the
93       latest    version    of    this    page,    can     be     found     at
94       https://www.kernel.org/doc/man-pages/.
95
96
97
98                                  2021-03-22                      READDIR_R(3)
Impressum