fdatasync tests: EBADF tests.
authorBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 20:03:35 +0000 (22:03 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 20 Sep 2011 20:03:35 +0000 (22:03 +0200)
* tests/test-fdatasync.c (main): Add more tests for EBADF.

ChangeLog
tests/test-fdatasync.c

index 06a2fb2..d1bf875 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2011-09-20  Bruno Haible  <bruno@clisp.org>
 
+       fdatasync tests: EBADF tests.
+       * tests/test-fdatasync.c (main): Add more tests for EBADF.
+
        Tests for module 'fchown'.
        * modules/fchown-tests: New file.
        * tests/test-fchown.c: New file.
index d35096d..a394a4c 100644 (file)
@@ -32,18 +32,29 @@ main (void)
   int fd;
   const char *file = "test-fdatasync.txt";
 
+  /* Assuming stdin and stdout are ttys, fdatasync is allowed to fail, but
+     may succeed as an extension.  */
   for (fd = 0; fd < 2; fd++)
     if (fdatasync (fd) != 0)
       {
         ASSERT (errno == EINVAL /* POSIX */
                 || errno == ENOTSUP /* seen on MacOS X 10.5 */
                 || errno == EBADF /* seen on AIX 7.1 */
+                || errno == EIO /* seen on mingw */
                 );
       }
 
-  errno = 0;
-  ASSERT (fdatasync (-1) == -1);
-  ASSERT (errno == EBADF);
+  /* fdatasync must fail on invalid fd.  */
+  {
+    errno = 0;
+    ASSERT (fdatasync (-1) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (fdatasync (99) == -1);
+    ASSERT (errno == EBADF);
+  }
 
   fd = open (file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
   ASSERT (0 <= fd);