From: Paul Eggert Date: Mon, 23 Mar 2015 02:47:24 +0000 (-0700) Subject: fdopendir-tests: test it does not close its arg X-Git-Tag: v1.0~7111 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d164bf67cc2d471facdd5d3b09f80f3688b3a21b;p=gnulib.git 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 --- diff --git a/ChangeLog b/ChangeLog index e645adca33..df175fd1af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-03-22 Paul Eggert + + 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 gitlog-to-changelog: trim trailing white space 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;