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 _BSD_SOURCE || _SVID_SOURCE
18 || /* Since glibc 2.10: */
19 (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)
20
22 The function dirfd() returns the file descriptor associated with the
23 directory stream dirp.
24
25 This descriptor is the one used internally by the directory stream. As
26 a result, it is useful only for functions which do not depend on or
27 alter the file position, such as fstat(2) and fchdir(2). It will be
28 automatically closed when closedir(3) is called.
29
31 On success, a nonnegative file descriptor is returned. On error, -1 is
32 returned, and errno is set to indicate the cause of the error.
33
35 POSIX.1-2008 specifies two errors, neither of which is returned by the
36 current implementation.
37
38 EINVAL dirp does not refer to a valid directory stream.
39
40 ENOTSUP
41 The implementation does not support the association of a file
42 descriptor with a directory.
43
45 Multithreading (see pthreads(7))
46 The dirfd() function is thread-safe.
47
49 POSIX.1-2008. This function was a BSD extension, present in 4.3BSD-
50 Reno, not in 4.2BSD.
51
53 The prototype for dirfd() is available only if _BSD_SOURCE or
54 _SVID_SOURCE is defined.
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 3.53 of the Linux man-pages project. A
62 description of the project, and information about reporting bugs, can
63 be found at http://www.kernel.org/doc/man-pages/.
64
65
66
67Linux 2013-07-05 DIRFD(3)