summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-03-22 19:47:24 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2015-03-22 19:47:50 -0700
commitd164bf67cc2d471facdd5d3b09f80f3688b3a21b (patch)
treed55ac67703bc86c9f9a17a818bac8a6ed19d5cb1 /tests
parent2b93079a5d1baa4d6ce9c90ef92cb0b98faabff2 (diff)
downloadgnulib-d164bf67cc2d471facdd5d3b09f80f3688b3a21b.tar.gz
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
Diffstat (limited to 'tests')
-rw-r--r--tests/test-fdopendir.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/test-fdopendir.c b/tests/test-fdopendir.c
index 1afbf9db39..8fd43824e9 100644
--- a/tests/test-fdopendir.c
+++ b/tests/test-fdopendir.c
@@ -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;