1dirfd(3) Library Functions Manual dirfd(3)
2
3
4
6 dirfd - get directory stream file descriptor
7
9 Standard C library (libc, -lc)
10
12 #include <sys/types.h>
13 #include <dirent.h>
14
15 int dirfd(DIR *dirp);
16
17 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19 dirfd():
20 /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200809L
21 || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
22
24 The function dirfd() returns the file descriptor associated with the
25 directory stream dirp.
26
27 This file descriptor is the one used internally by the directory
28 stream. As a result, it is useful only for functions which do not de‐
29 pend on or alter the file position, such as fstat(2) and fchdir(2). It
30 will be automatically closed when closedir(3) is called.
31
33 On success, dirfd() returns a file descriptor (a nonnegative integer).
34 On error, -1 is returned, and errno is set to indicate the error.
35
37 POSIX.1-2008 specifies two errors, neither of which is returned by the
38 current implementation.
39
40 EINVAL dirp does not refer to a valid directory stream.
41
42 ENOTSUP
43 The implementation does not support the association of a file
44 descriptor with a directory.
45
47 For an explanation of the terms used in this section, see at‐
48 tributes(7).
49
50 ┌────────────────────────────────────────────┬───────────────┬─────────┐
51 │Interface │ Attribute │ Value │
52 ├────────────────────────────────────────────┼───────────────┼─────────┤
53 │dirfd() │ Thread safety │ MT-Safe │
54 └────────────────────────────────────────────┴───────────────┴─────────┘
55
57 POSIX.1-2008.
58
60 4.3BSD-Reno (not in 4.2BSD).
61
63 open(2), openat(2), closedir(3), opendir(3), readdir(3), rewinddir(3),
64 scandir(3), seekdir(3), telldir(3)
65
66
67
68Linux man-pages 6.04 2023-03-30 dirfd(3)