file descriptor before returning. This makes our replacement
implementation a little closer to Solaris's, where fdopendir
ties the file descriptor to the returned DIR* pointer.
If either the save_cwd or the restore_cwd fails (relatively unlikely,
and usually indicative of a problem that deserves close attention),
then give a diagnostic and exit nonzero.
- Otherwise, this function works just like Solaris' fdopendir. */
+ Otherwise, this function works just like Solaris' fdopendir.
+
+ W A R N I N G:
+ Unlike the other fd-related functions here, this one
+ effectively consumes its FD parameter. The caller should not
+ close or otherwise manipulate FD after calling this function. */
DIR *
fdopendir (int fd)
{
{
saved_errno = errno;
free_cwd (&saved_cwd);
+ close (fd);
errno = saved_errno;
return NULL;
}
openat_restore_fail (errno);
free_cwd (&saved_cwd);
+ close (fd);
errno = saved_errno;
return dir;