OSDN Git Service

c77b0c68c6e5237009cab82fdf692008c7eb3be2
[linuxjm/LDP_man-pages.git] / original / man3 / dirfd.3
1 .\" Copyright (C) 2002 Andries Brouwer (aeb@cwi.nl)
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 .TH DIRFD 3 2010-09-26 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 dirfd \- get directory stream file descriptor
26 .SH SYNOPSIS
27 .B #include <sys/types.h>
28 .br
29 .B #include <dirent.h>
30 .sp
31 .BI "int dirfd(DIR *" dirp );
32 .sp
33 .in -4n
34 Feature Test Macro Requirements for glibc (see
35 .BR feature_test_macros (7)):
36 .in
37 .sp
38 .BR dirfd ():
39 .br
40 .RS 4
41 .PD 0
42 .ad l
43 _BSD_SOURCE || _SVID_SOURCE
44 .br
45 || /* Since glibc 2.10: */
46 .RS 4
47 (_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
48 .RE
49 .PD
50 .RE
51 .ad
52 .SH DESCRIPTION
53 The function
54 .BR dirfd ()
55 returns the file descriptor associated with the directory stream
56 .IR dirp .
57 .LP
58 This descriptor is the one used internally by the directory stream.
59 As a result, it is only useful for functions which do not depend on
60 or alter the file position, such as
61 .BR fstat (2)
62 and
63 .BR fchdir (2).
64 It will be automatically closed when
65 .BR closedir (3)
66 is called.
67 .SH RETURN VALUE
68 On success, a nonnegative file descriptor is returned.
69 On error, \-1 is returned.
70 .SH ERRORS
71 POSIX.1-2008 specifies two errors,
72 neither of which is returned by the current
73 .\" glibc 2.8
74 implementation.
75 .TP
76 .B EINVAL
77 .I dirp
78 does not refer to a valid directory stream.
79 .TP
80 .B ENOTSUP
81 The implementation does not support the association of a file
82 descriptor with a directory.
83 .SH "CONFORMING TO"
84 POSIX.1-2008.
85 This function was a BSD extension, present in 4.3BSD-Reno, not in 4.2BSD.
86 .\" It is present in libc5 (since 5.1.2) and in glibc2.
87 .SH NOTES
88 The prototype for
89 .BR dirfd ()
90 is only available if
91 .B _BSD_SOURCE
92 or
93 .B _SVID_SOURCE
94 is defined.
95 .SH "SEE ALSO"
96 .BR open (2),
97 .BR closedir (3),
98 .BR opendir (3),
99 .BR readdir (3),
100 .BR rewinddir (3),
101 .BR scandir (3),
102 .BR seekdir (3),
103 .BR telldir (3)