Implementation status: to be implemented


#include <dirent.h>

int dirfd(DIR *dirp);


The dirfd() function computes a file descriptor referring to the same directory as the dirp argument. This file descriptor is closed by a call to closedir().
The file descriptor, or the state of the associated description, can be modified only by: closedir(), readdir(), readdir_r(), rewinddir(), or seekdir(). After attempt to close this descriptor another way, the behaviour is undefined.

dirp - a pointer to the DIR data structure.

Return value

On success an integer containing a file descriptor for the directory pointed to by dirp,
otherwise -1 is returned and errno set to indicate the error.


[EINVAL] - the dirp argument does not refer to a valid directory stream.

Implementation tasks

  • Implement the dirfd() function.