Debian Codegraph @

upstream/debian-trixie/man3/dirfd.3

raw
1 '\" t
2 .\" Copyright (C) 2002 Andries Brouwer ([email protected])
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH dirfd 3 2024-05-02 "Linux man-pages 6.9.1"
7 .SH NAME
8 dirfd \- get directory stream file descriptor
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/types.h>
15 .B #include <dirent.h>
16 .P
17 .BI "int dirfd(DIR *" dirp );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR dirfd ():
26 .nf
27 /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200809L
28 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
29 .fi
30 .SH DESCRIPTION
31 The function
32 .BR dirfd ()
33 returns the file descriptor associated with the directory stream
34 .IR dirp .
35 .P
36 This file descriptor is the one used internally by the directory stream.
37 As a result, it is useful only for functions which do not depend on
38 or alter the file position, such as
39 .BR fstat (2)
40 and
41 .BR fchdir (2).
42 It will be automatically closed when
43 .BR closedir (3)
44 is called.
45 .SH RETURN VALUE
46 On success,
47 .BR dirfd ()
48 returns a file descriptor (a nonnegative integer).
49 On error, \-1 is returned, and
50 .I errno
51 is set to indicate the error.
52 .SH ERRORS
53 POSIX.1-2008 specifies two errors,
54 neither of which is returned by the current
55 .\" glibc 2.8
56 implementation.
57 .TP
58 .B EINVAL
59 .I dirp
60 does not refer to a valid directory stream.
61 .TP
62 .B ENOTSUP
63 The implementation does not support the association of a file
64 descriptor with a directory.
65 .SH ATTRIBUTES
66 For an explanation of the terms used in this section, see
67 .BR attributes (7).
68 .TS
69 allbox;
70 lbx lb lb
71 l l l.
72 Interface Attribute Value
73 T{
74 .na
75 .nh
76 .BR dirfd ()
77 T} Thread safety MT-Safe
78 .TE
79 .SH STANDARDS
80 POSIX.1-2008.
81 .SH HISTORY
82 4.3BSD-Reno (not in 4.2BSD).
83 .\" It is present in libc5 (since 5.1.2) and in glibc 2.
84 .SH SEE ALSO
85 .BR open (2),
86 .BR openat (2),
87 .BR closedir (3),
88 .BR opendir (3),
89 .BR readdir (3),
90 .BR rewinddir (3),
91 .BR scandir (3),
92 .BR seekdir (3),
93 .BR telldir (3)