]> Savannah Git Hosting - gnulib.git/commitdiff
fdopendir: port better to MinGW
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Mar 2015 19:11:07 +0000 (12:11 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 19 Mar 2015 19:13:27 +0000 (12:13 -0700)
* lib/fdopendir.c (fd_clone_opendir) [REPLACE_FCHDIR]:
Use 'dup' if dirfd fails.  Suggested by Eli Zaretskii in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-03/msg00033.html
* modules/fdopendir (Depends-on): Add dirfd.

ChangeLog
lib/fdopendir.c
modules/fdopendir

index 18d90e2d7e402fb2e724fa40771d201220e84236..709dfffe093d3f1f02a7afac4d3a95f45a197950 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-03-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       fdopendir: port better to MinGW
+       * lib/fdopendir.c (fd_clone_opendir) [REPLACE_FCHDIR]:
+       Use 'dup' if dirfd fails.  Suggested by Eli Zaretskii in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2015-03/msg00033.html
+       * modules/fdopendir (Depends-on): Add dirfd.
+
 2015-03-18  Paul Eggert  <eggert@cs.ucla.edu>
 
        fdopendir: fix typo in comment
index 117baa9993b0b05347732dae762c9710736c7480..837a8219b3399f7431c70169e0694ee7cb523f1d 100644 (file)
@@ -156,7 +156,16 @@ fd_clone_opendir (int fd, struct saved_cwd const *cwd)
       if (! dir && EXPECTED_ERRNO (saved_errno))
         {
           char const *name = _gl_directory_name (fd);
-          return (name ? opendir (name) : NULL);
+          DIR *dp = name ? opendir (name) : NULL;
+
+          /* The caller has done an elaborate dance to arrange for opendir to
+             consume just the right file descriptor.  If dirfd returns -1,
+             though, we're on a system like mingw where opendir does not
+             consume a file descriptor.  Consume it via 'dup' instead.  */
+          if (dp && dirfd (dp) < 0)
+            dup (fd);
+
+          return dp;
         }
 # endif
       errno = saved_errno;
index ee9a875396c2669919d229281b650b18baffc0fb..2d03867ecc3bf28caed50cdd011869322915c682 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 dirent
 extensions
 at-internal     [test $HAVE_FDOPENDIR = 0]
+dirfd           [test $HAVE_FDOPENDIR = 0]
 dup             [test $HAVE_FDOPENDIR = 0]
 errno           [test $HAVE_FDOPENDIR = 0]
 fchdir          [test $HAVE_FDOPENDIR = 0]