fdopendir: preserve argument fd before returning
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Sep 2010 19:21:47 +0000 (12:21 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 13 Sep 2010 19:22:05 +0000 (12:22 -0700)
commit970c9038e4cca46e1b037ae0a6d574dfae6a7327
tree5a40e33b2d4134f9d201ee27ca8c3c5e736c78d1
parente2b0e1a20b071f1516829ffe5bbddbc41007fd63
fdopendir: preserve argument fd before returning

* lib/fdopendir.c: Adjust comments to say POSIX, not Solaris.
(fdopendir_with_dup, fd_clone_opendir): New static functions.
(fdopendir): Use them, arranging for FD to be open to the same
directory that it was when it started.  (It might be temporarily
closed while fdopendir is running, so this not thread- or
signal-safe.)  Be careful to do the right thing even when file
descriptors are scarce and dup fails with errno == EMFILE.  See
<http://lists.gnu.org/archive/html/bug-gnulib/2010-09/msg00208.html>.
ChangeLog
lib/fdopendir.c