changeset 17612:6553b95ff49c

fdopen-tests: port to Tru64 * tests/test-fdopen.c (main): Don't invoke fdopen on a file descriptors that is not open, as POSIX doesn't specify the resulting behavior and the test does not work on Tru64. Problem reported by Steven M. Schweda in: http://lists.gnu.org/archive/html/bug-gnulib/2014-01/msg00079.html
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 20 Jan 2014 22:12:56 -0800
parents c1b6267bf825
children 4a52ecda755c
files ChangeLog tests/test-fdopen.c
diffstat 2 files changed, 21 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2014-01-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+	fdopen-tests: port to Tru64
+	* tests/test-fdopen.c (main): Don't invoke fdopen on a file
+	descriptors that is not open, as POSIX doesn't specify the
+	resulting behavior and the test does not work on Tru64.
+	Problem reported by Steven M. Schweda in:
+	http://lists.gnu.org/archive/html/bug-gnulib/2014-01/msg00079.html
+
 	stdalign: port to HP-UX compilers
 	* lib/stdalign.in.h (_Alignas): Use __attribute__ (__aligned__ (x))
 	if __HP_cc or __HP_aCC are nonzero.
--- a/tests/test-fdopen.c
+++ b/tests/test-fdopen.c
@@ -29,28 +29,21 @@
 int
 main (void)
 {
-  /* Test behaviour for invalid file descriptors.  */
-  {
-    FILE *fp;
+  /* Test behavior on failure.  POSIX makes it hard to check for
+     failure, since the behavior is not well-defined on invalid file
+     descriptors, so try fdopen 1000 times and if that's not enough to
+     fail due to EMFILE, so be it.  */
 
-    errno = 0;
-    fp = fdopen (-1, "r");
-    if (fp == NULL)
-      ASSERT (errno == EBADF);
-    else
-      fclose (fp);
-  }
-  {
-    FILE *fp;
-
-    close (99);
-    errno = 0;
-    fp = fdopen (99, "r");
-    if (fp == NULL)
-      ASSERT (errno == EBADF);
-    else
-      fclose (fp);
-  }
+  int i;
+  for (i = 0; i < 1000; i++)
+    {
+      errno = 0;
+      if (! fdopen (STDOUT_FILENO, "w"))
+        {
+          ASSERT (errno != 0);
+          break;
+        }
+    }
 
   return 0;
 }