]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/opendir.3
system.3: ffix
[thirdparty/man-pages.git] / man3 / opendir.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\" 386BSD man pages
29 .\" Modified Sat Jul 24 18:46:01 1993 by Rik Faith (faith@cs.unc.edu)
30 .\" Modified 11 June 1995 by Andries Brouwer (aeb@cwi.nl)
31 .\" 2007-07-30 Ulrich Drepper <drepper@redhat.com>: document fdopendir().
32 .TH OPENDIR 3 2017-09-15 "GNU" "Linux Programmer's Manual"
33 .SH NAME
34 opendir, fdopendir \- open a directory
35 .SH SYNOPSIS
36 .nf
37 .B #include <sys/types.h>
38 .B #include <dirent.h>
39 .PP
40 .BI "DIR *opendir(const char *" name );
41 .BI "DIR *fdopendir(int " fd );
42 .fi
43 .PP
44 .in -4n
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .in
48 .PP
49 .BR fdopendir ():
50 .PD 0
51 .ad l
52 .RS 4
53 .TP 4
54 Since glibc 2.10:
55 _POSIX_C_SOURCE\ >=\ 200809L
56 .TP
57 Before glibc 2.10:
58 _GNU_SOURCE
59 .RE
60 .ad
61 .PD
62 .SH DESCRIPTION
63 The
64 .BR opendir ()
65 function opens a directory stream corresponding to the
66 directory \fIname\fP, and returns a pointer to the directory stream.
67 The stream is positioned at the first entry in the directory.
68 .PP
69 The
70 .BR fdopendir ()
71 function
72 is like
73 .BR opendir (),
74 but returns a directory stream for the directory referred
75 to by the open file descriptor
76 .IR fd .
77 After a successful call to
78 .BR fdopendir (),
79 .I fd
80 is used internally by the implementation,
81 and should not otherwise be used by the application.
82 .SH RETURN VALUE
83 The
84 .BR opendir ()
85 and
86 .BR fdopendir ()
87 functions return a pointer to the directory stream.
88 On error, NULL is returned, and
89 .I errno
90 is set appropriately.
91 .SH ERRORS
92 .TP
93 .B EACCES
94 Permission denied.
95 .TP
96 .B EBADF
97 .I fd
98 is not a valid file descriptor opened for reading.
99 .TP
100 .B EMFILE
101 The per-process limit on the number of open file descriptors has been reached.
102 .TP
103 .B ENFILE
104 The system-wide limit on the total number of open files has been reached.
105 .TP
106 .B ENOENT
107 Directory does not exist, or \fIname\fP is an empty string.
108 .TP
109 .B ENOMEM
110 Insufficient memory to complete the operation.
111 .TP
112 .B ENOTDIR
113 \fIname\fP is not a directory.
114 .SH VERSIONS
115 .BR fdopendir ()
116 is available in glibc since version 2.4.
117 .SH ATTRIBUTES
118 For an explanation of the terms used in this section, see
119 .BR attributes (7).
120 .TS
121 allbox;
122 lbw22 lb lb
123 l l l.
124 Interface Attribute Value
125 T{
126 .BR opendir (),
127 .BR fdopendir ()
128 T} Thread safety MT-Safe
129 .TE
130 .SH CONFORMING TO
131 .BR opendir ()
132 is present on SVr4, 4.3BSD, and specified in POSIX.1-2001.
133 .BR fdopendir ()
134 is specified in POSIX.1-2008.
135 .SH NOTES
136 Filename entries can be read from a directory stream using
137 .BR readdir (3).
138 .PP
139 The underlying file descriptor of the directory stream can be obtained using
140 .BR dirfd (3).
141 .PP
142 The
143 .BR opendir ()
144 function sets the close-on-exec flag for the file descriptor underlying the
145 .IR "DIR *" .
146 The
147 .BR fdopendir ()
148 function leaves the setting of the close-on-exec
149 flag unchanged for the file descriptor,
150 .IR fd .
151 POSIX.1-200x leaves it unspecified whether a successful call to
152 .BR fdopendir ()
153 will set the close-on-exec flag for the file descriptor,
154 .IR fd .
155 .SH SEE ALSO
156 .BR open (2),
157 .BR closedir (3),
158 .BR dirfd (3),
159 .BR readdir (3),
160 .BR rewinddir (3),
161 .BR scandir (3),
162 .BR seekdir (3),
163 .BR telldir (3)