1 .\" Copyright (C) 2002 Andries Brouwer (aeb@cwi.nl)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH DIRFD 3 2008-08-21 "Linux" "Linux Programmer's Manual"
25 dirfd \- get directory stream file descriptor
27 .B #include <sys/types.h>
29 .B #include <dirent.h>
31 .BI "int dirfd(DIR *" dirp );
34 Feature Test Macro Requirements for glibc (see
35 .BR feature_test_macros (7)):
39 _BSD_SOURCE || _SVID_SOURCE
43 returns the file descriptor associated with the directory stream
46 This descriptor is the one used internally by the directory stream.
47 As a result, it is only useful for functions which do not depend on
48 or alter the file position, such as
52 It will be automatically closed when
56 On success, a nonnegative file descriptor is returned.
57 On error, \-1 is returned.
59 POSIX.1-2008 specifies two errors,
60 neither of which is returned by the current
66 does not refer to a valid directory stream.
69 The implementation does not support the association of a file
70 descriptor with a directory.
73 This function was a BSD extension, present in 4.3BSD-Reno, not in 4.2BSD.
74 .\" It is present in libc5 (since 5.1.2) and in glibc2.