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