 <p>The <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html" rel="nofollow">POSIX description</a> of <code>fdopendir()</code> says:</p> <blockquote> <p>Upon calling closedir() the file descriptor shall be closed.</p> </blockquote> <p>So the descriptor is likely to be closed by the time you call <code>openat()</code>.</p> <p>And this is from <a href="http://manpages.ubuntu.com/manpages/quantal/man3/opendir.3.html" rel="nofollow">a typical Linux man page</a> for <code>fdopendir():</code></p> <blockquote> <p>After a successful call to fdopendir(), fd is used internally by the implementation, and should not otherwise be used by the application.</p> </blockquote>