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 versions <= 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
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

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 cause of the
32       error.
33

ERRORS

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

ATTRIBUTES

45       For   an   explanation   of   the  terms  used  in  this  section,  see
46       attributes(7).
47
48       ┌──────────┬───────────────┬─────────┐
49Interface Attribute     Value   
50       ├──────────┼───────────────┼─────────┤
51dirfd()   │ Thread safety │ MT-Safe │
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.07 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                             2020-04-11                          DIRFD(3)
Impressum