Debian Codegraph @

upstream/debian-unstable/man3/opendir.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH opendir 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 opendir, fdopendir \- open a directory
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/types.h>
16 .B #include <dirent.h>
17 .P
18 .BI "DIR *opendir(const char *" name );
19 .BI "DIR *fdopendir(int " fd );
20 .fi
21 .P
22 .RS -4
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
25 .RE
26 .P
27 .BR fdopendir ():
28 .nf
29 Since glibc 2.10:
30 _POSIX_C_SOURCE >= 200809L
31 Before glibc 2.10:
32 _GNU_SOURCE
33 .fi
34 .SH DESCRIPTION
35 The
36 .BR opendir ()
37 function opens a directory stream corresponding to the
38 directory
39 .IR name ,
40 and returns a pointer to the directory stream.
41 The stream is positioned at the first entry in the directory.
42 .P
43 The
44 .BR fdopendir ()
45 function
46 is like
47 .BR opendir (),
48 but returns a directory stream for the directory referred
49 to by the open file descriptor
50 .IR fd .
51 After a successful call to
52 .BR fdopendir (),
53 .I fd
54 is used internally by the implementation,
55 and should not otherwise be used by the application.
56 .SH RETURN VALUE
57 The
58 .BR opendir ()
59 and
60 .BR fdopendir ()
61 functions return a pointer to the directory stream.
62 On error, NULL is returned, and
63 .I errno
64 is set to indicate the error.
65 .SH ERRORS
66 .TP
67 .B EACCES
68 Permission denied.
69 .TP
70 .B EBADF
71 .I fd
72 is not a valid file descriptor opened for reading.
73 .TP
74 .B EMFILE
75 The per-process limit on the number of open file descriptors has been reached.
76 .TP
77 .B ENAMETOOLONG
78 .I name
79 was too long.
80 .TP
81 .B ENFILE
82 The system-wide limit on the total number of open files has been reached.
83 .TP
84 .B ENOENT
85 Directory does not exist, or
86 .I name
87 is an empty string.
88 .TP
89 .B ENOMEM
90 Insufficient memory to complete the operation.
91 .TP
92 .B ENOTDIR
93 .I name
94 is not a directory.
95 .SH ATTRIBUTES
96 For an explanation of the terms used in this section, see
97 .BR attributes (7).
98 .TS
99 allbox;
100 lbx lb lb
101 l l l.
102 Interface Attribute Value
103 T{
104 .na
105 .nh
106 .BR opendir (),
107 .BR fdopendir ()
108 T} Thread safety MT-Safe
109 .TE
110 .SH STANDARDS
111 POSIX.1-2008.
112 .SH STANDARDS
113 .TP
114 .BR opendir ()
115 SVr4, 4.3BSD, POSIX.1-2001.
116 .TP
117 .BR fdopendir ()
118 POSIX.1-2008.
119 glibc 2.4.
120 .SH NOTES
121 Filename entries can be read from a directory stream using
122 .BR readdir (3).
123 .P
124 The underlying file descriptor of the directory stream can be obtained using
125 .BR dirfd (3).
126 .P
127 The
128 .BR opendir ()
129 function sets the close-on-exec flag for the file descriptor underlying the
130 .IR "DIR *" .
131 The
132 .BR fdopendir ()
133 function leaves the setting of the close-on-exec
134 flag unchanged for the file descriptor,
135 .IR fd .
136 POSIX.1-200x leaves it unspecified whether a successful call to
137 .BR fdopendir ()
138 will set the close-on-exec flag for the file descriptor,
139 .IR fd .
140 .SH SEE ALSO
141 .BR open (2),
142 .BR closedir (3),
143 .BR dirfd (3),
144 .BR readdir (3),
145 .BR rewinddir (3),
146 .BR scandir (3),
147 .BR seekdir (3),
148 .BR telldir (3)