The underlying file descriptor of the directory stream can be obtained using dirfd (3) . The opendir () function sets the close-on-exec flag for the file descriptor underlying the DIR *.