1DIRFD(3) Linux Programmer's Manual DIRFD(3)
2
3
4
6 dirfd - get directory stream file descriptor
7
9 #include <sys/types.h>
10 #include <dirent.h>
11
12 int dirfd(DIR *dirp);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 dirfd():
17 /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200809L
18 || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
19
21 The function dirfd() returns the file descriptor associated with the
22 directory stream dirp.
23
24 This file descriptor is the one used internally by the directory
25 stream. As a result, it is useful only for functions which do not
26 depend on or alter the file position, such as fstat(2) and fchdir(2).
27 It will be automatically closed when closedir(3) is called.
28
30 On success, a nonnegative file descriptor is returned. On error, -1 is
31 returned, and errno is set to indicate the cause of the error.
32
34 POSIX.1-2008 specifies two errors, neither of which is returned by the
35 current implementation.
36
37 EINVAL dirp does not refer to a valid directory stream.
38
39 ENOTSUP
40 The implementation does not support the association of a file
41 descriptor with a directory.
42
44 For an explanation of the terms used in this section, see
45 attributes(7).
46
47 ┌──────────┬───────────────┬─────────┐
48 │Interface │ Attribute │ Value │
49 ├──────────┼───────────────┼─────────┤
50 │dirfd() │ Thread safety │ MT-Safe │
51 └──────────┴───────────────┴─────────┘
53 POSIX.1-2008. This function was a BSD extension, present in 4.3BSD-
54 Reno, not in 4.2BSD.
55
57 open(2), closedir(3), opendir(3), readdir(3), rewinddir(3), scandir(3),
58 seekdir(3), telldir(3)
59
61 This page is part of release 4.16 of the Linux man-pages project. A
62 description of the project, information about reporting bugs, and the
63 latest version of this page, can be found at
64 https://www.kernel.org/doc/man-pages/.
65
66
67
68Linux 2016-03-15 DIRFD(3)