1OPENDIR(3) Linux Programmer's Manual OPENDIR(3)
2
3
4
6 opendir, fdopendir - open a directory
7
9 #include <sys/types.h>
10 #include <dirent.h>
11
12 DIR *opendir(const char *name);
13 DIR *fdopendir(int fd);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 fdopendir():
18 Since glibc 2.10:
19 _POSIX_C_SOURCE >= 200809L
20 Before glibc 2.10:
21 _GNU_SOURCE
22
24 The opendir() function opens a directory stream corresponding to the
25 directory name, and returns a pointer to the directory stream. The
26 stream is positioned at the first entry in the directory.
27
28 The fdopendir() function is like opendir(), but returns a directory
29 stream for the directory referred to by the open file descriptor fd.
30 After a successful call to fdopendir(), fd is used internally by the
31 implementation, and should not otherwise be used by the application.
32
34 The opendir() and fdopendir() functions return a pointer to the direc‐
35 tory stream. On error, NULL is returned, and errno is set to indicate
36 the error.
37
39 EACCES Permission denied.
40
41 EBADF fd is not a valid file descriptor opened for reading.
42
43 EMFILE The per-process limit on the number of open file descriptors has
44 been reached.
45
46 ENFILE The system-wide limit on the total number of open files has been
47 reached.
48
49 ENOENT Directory does not exist, or name is an empty string.
50
51 ENOMEM Insufficient memory to complete the operation.
52
53 ENOTDIR
54 name is not a directory.
55
57 fdopendir() is available in glibc since version 2.4.
58
60 For an explanation of the terms used in this section, see at‐
61 tributes(7).
62
63 ┌────────────────────────────────────────────┬───────────────┬─────────┐
64 │Interface │ Attribute │ Value │
65 ├────────────────────────────────────────────┼───────────────┼─────────┤
66 │opendir(), fdopendir() │ Thread safety │ MT-Safe │
67 └────────────────────────────────────────────┴───────────────┴─────────┘
68
70 opendir() is present on SVr4, 4.3BSD, and specified in POSIX.1-2001.
71 fdopendir() is specified in POSIX.1-2008.
72
74 Filename entries can be read from a directory stream using readdir(3).
75
76 The underlying file descriptor of the directory stream can be obtained
77 using dirfd(3).
78
79 The opendir() function sets the close-on-exec flag for the file de‐
80 scriptor underlying the DIR *. The fdopendir() function leaves the
81 setting of the close-on-exec flag unchanged for the file descriptor,
82 fd. POSIX.1-200x leaves it unspecified whether a successful call to
83 fdopendir() will set the close-on-exec flag for the file descriptor,
84 fd.
85
87 open(2), closedir(3), dirfd(3), readdir(3), rewinddir(3), scandir(3),
88 seekdir(3), telldir(3)
89
91 This page is part of release 5.12 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
98GNU 2021-03-22 OPENDIR(3)