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 appropri‐
36 ately.
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
61 attributes(7).
62
63 ┌───────────────────────┬───────────────┬─────────┐
64 │Interface │ Attribute │ Value │
65 ├───────────────────────┼───────────────┼─────────┤
66 │opendir(), fdopendir() │ Thread safety │ MT-Safe │
67 └───────────────────────┴───────────────┴─────────┘
69 opendir() is present on SVr4, 4.3BSD, and specified in POSIX.1-2001.
70 fdopendir() is specified in POSIX.1-2008.
71
73 Filename entries can be read from a directory stream using readdir(3).
74
75 The underlying file descriptor of the directory stream can be obtained
76 using dirfd(3).
77
78 The opendir() function sets the close-on-exec flag for the file
79 descriptor underlying the DIR *. The fdopendir() function leaves the
80 setting of the close-on-exec flag unchanged for the file descriptor,
81 fd. POSIX.1-200x leaves it unspecified whether a successful call to
82 fdopendir() will set the close-on-exec flag for the file descriptor,
83 fd.
84
86 open(2), closedir(3), dirfd(3), readdir(3), rewinddir(3), scandir(3),
87 seekdir(3), telldir(3)
88
90 This page is part of release 4.16 of the Linux man-pages project. A
91 description of the project, information about reporting bugs, and the
92 latest version of this page, can be found at
93 https://www.kernel.org/doc/man-pages/.
94
95
96
97GNU 2017-09-15 OPENDIR(3)