Extracts the file descriptor used by a DIR stream.
Standard C Library (libc.a)
#include <dirent.h>
int dirfd(dirp);
DIR *dirp;
The dirfd subroutine returns a file descriptor that refers to the directory pointed to by the dirp argument. This file descriptor is closed by a call to the closedir subroutine. If an attempt is made to close the file descriptor, and to modify the state of the associated description, other than through the closedir, readdir, readdir_r, or rewinddir subroutines, the behavior is undefined.
If successful, the dirfd subroutine returns an integer that contains a file descriptor for the stream pointed to by dirp argument. Otherwise, the dirfd subroutine returns -1 and sets the errno global variable to indicate the error.
The dirfd subroutine might fail if the following is true:
Item | Description |
---|---|
EINVAL | The dirp argument does not refer to a valid directory stream. |
ENOTSUP | The implementation does not support the association of a file descriptor with a directory. |