]> Savannah Git Hosting - gnulib.git/commitdiff
fdopendir-tests: test it does not close its arg
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 23 Mar 2015 02:47:24 +0000 (19:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 23 Mar 2015 02:47:50 +0000 (19:47 -0700)
* tests/test-fdopendir.c (main): Test that fdopendir does not
close its argument.  From a suggestion by David Grayson in:
http://lists.gnu.org/archive/html/bug-gnulib/2015-03/msg00039.html

ChangeLog
tests/test-fdopendir.c

index e645adca3300eafbcbcabb584b4454a3fc687e3a..df175fd1affa547ca0ef8b27acb75a2072d3b1ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-03-22  Paul Eggert  <eggert@cs.ucla.edu>
+
+       fdopendir-tests: test it does not close its arg
+       * tests/test-fdopendir.c (main): Test that fdopendir does not
+       close its argument.  From a suggestion by David Grayson in:
+       http://lists.gnu.org/archive/html/bug-gnulib/2015-03/msg00039.html
+
 2015-03-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        gitlog-to-changelog: trim trailing white space
index 1afbf9db39b31e2185002bef021fe4736747ea52..8fd43824e9cf5de89afd9f172944b1f16196ba11 100644 (file)
@@ -64,11 +64,15 @@ main (int argc _GL_UNUSED, char *argv[])
   fd = open (".", O_RDONLY);
   ASSERT (0 <= fd);
   d = fdopendir (fd);
-  /* We know that fd is now out of our reach, but it is not specified
-     whether it is closed now or at the closedir.  We also can't
-     guarantee whether dirfd returns fd, some other descriptor, or
-     -1.  */
   ASSERT (d);
+  /* fdopendir should not close fd.  */
+  ASSERT (dup2 (fd, fd) == fd);
+
+  /* Don't test dirfd here.  dirfd (d) must return fd on current POSIX
+     platforms, but on pre-2008 platforms or on non-POSIX platforms
+     dirfd (fd) might return some other descriptor, or -1, and gnulib
+     does not work around this porting problem.  */
+
   ASSERT (closedir (d) == 0);
   /* Now we can guarantee that fd must be closed.  */
   errno = 0;