1DIRFD(3)                   Linux Programmer's Manual                  DIRFD(3)
2
3
4

NAME

6       dirfd - get directory stream file descriptor
7

SYNOPSIS

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 <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
19

DESCRIPTION

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 de‐
26       pend on or alter the file position, such as fstat(2) and fchdir(2).  It
27       will be automatically closed when closedir(3) is called.
28

RETURN VALUE

30       On  success, dirfd() returns a file descriptor (a nonnegative integer).
31       On error, -1 is returned, and errno is set to indicate the error.
32

ERRORS

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

ATTRIBUTES

44       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
45       tributes(7).
46
47       ┌────────────────────────────────────────────┬───────────────┬─────────┐
48Interface                                   Attribute     Value   
49       ├────────────────────────────────────────────┼───────────────┼─────────┤
50dirfd()                                     │ Thread safety │ MT-Safe │
51       └────────────────────────────────────────────┴───────────────┴─────────┘
52

CONFORMING TO

54       POSIX.1-2008.   This  function  was a BSD extension, present in 4.3BSD-
55       Reno, not in 4.2BSD.
56

SEE ALSO

58       open(2), openat(2), closedir(3), opendir(3), readdir(3),  rewinddir(3),
59       scandir(3), seekdir(3), telldir(3)
60

COLOPHON

62       This  page  is  part of release 5.13 of the Linux man-pages project.  A
63       description of the project, information about reporting bugs,  and  the
64       latest     version     of     this    page,    can    be    found    at
65       https://www.kernel.org/doc/man-pages/.
66
67
68
69Linux                             2021-03-22                          DIRFD(3)
Impressum