ioctl_tty.2: Update DTR example
[man-pages.git] / man3 / opendir.3
blob464bb4f8c5788980d016de4f52f673c20018f84b
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  2021-03-22 "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 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .PP
49 .BR fdopendir ():
50 .nf
51     Since glibc 2.10:
52         _POSIX_C_SOURCE >= 200809L
53     Before glibc 2.10:
54         _GNU_SOURCE
55 .fi
56 .SH DESCRIPTION
57 The
58 .BR opendir ()
59 function opens a directory stream corresponding to the
60 directory \fIname\fP, and returns a pointer to the directory stream.
61 The stream is positioned at the first entry in the directory.
62 .PP
63 The
64 .BR fdopendir ()
65 function
66 is like
67 .BR opendir (),
68 but returns a directory stream for the directory referred
69 to by the open file descriptor
70 .IR fd .
71 After a successful call to
72 .BR fdopendir (),
73 .I fd
74 is used internally by the implementation,
75 and should not otherwise be used by the application.
76 .SH RETURN VALUE
77 The
78 .BR opendir ()
79 and
80 .BR fdopendir ()
81 functions return a pointer to the directory stream.
82 On error, NULL is returned, and
83 .I errno
84 is set to indicate the error.
85 .SH ERRORS
86 .TP
87 .B EACCES
88 Permission denied.
89 .TP
90 .B EBADF
91 .I fd
92 is not a valid file descriptor opened for reading.
93 .TP
94 .B EMFILE
95 The per-process limit on the number of open file descriptors has been reached.
96 .TP
97 .B ENFILE
98 The system-wide limit on the total number of open files has been reached.
99 .TP
100 .B ENOENT
101 Directory does not exist, or \fIname\fP is an empty string.
103 .B ENOMEM
104 Insufficient memory to complete the operation.
106 .B ENOTDIR
107 \fIname\fP is not a directory.
108 .SH VERSIONS
109 .BR fdopendir ()
110 is available in glibc since version 2.4.
111 .SH ATTRIBUTES
112 For an explanation of the terms used in this section, see
113 .BR attributes (7).
114 .ad l
117 allbox;
118 lbx lb lb
119 l l l.
120 Interface       Attribute       Value
122 .BR opendir (),
123 .BR fdopendir ()
124 T}      Thread safety   MT-Safe
128 .sp 1
129 .SH CONFORMING TO
130 .BR opendir ()
131 is present on SVr4, 4.3BSD, and specified in POSIX.1-2001.
132 .BR fdopendir ()
133 is specified in POSIX.1-2008.
134 .SH NOTES
135 Filename entries can be read from a directory stream using
136 .BR readdir (3).
138 The underlying file descriptor of the directory stream can be obtained using
139 .BR dirfd (3).
142 .BR opendir ()
143 function sets the close-on-exec flag for the file descriptor underlying the
144 .IR "DIR *" .
146 .BR fdopendir ()
147 function leaves the setting of the close-on-exec
148 flag unchanged for the file descriptor,
149 .IR fd .
150 POSIX.1-200x leaves it unspecified whether a successful call to
151 .BR fdopendir ()
152 will set the close-on-exec flag for the file descriptor,
153 .IR fd .
154 .SH SEE ALSO
155 .BR open (2),
156 .BR closedir (3),
157 .BR dirfd (3),
158 .BR readdir (3),
159 .BR rewinddir (3),
160 .BR scandir (3),
161 .BR seekdir (3),
162 .BR telldir (3)