]> Savannah Git Hosting - gnulib.git/commitdiff
supersede: Fix test failures on native Windows.
authorBruno Haible <bruno@clisp.org>
Sun, 20 Sep 2020 22:51:54 +0000 (00:51 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 20 Sep 2020 22:52:19 +0000 (00:52 +0200)
* lib/supersede.c (open_supersede): Handle non-regular files on native
Windows like on Solaris.
* tests/test-supersede-open.h (test_open_supersede): Use O_BINARY flag.

ChangeLog
lib/supersede.c
tests/test-supersede-open.h

index a7a0ce84030d72d236d5986b0eff84b3687d22c1..167c7e78931823b6caee8444513ac4ee64b162c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-09-20  Bruno Haible  <bruno@clisp.org>
+
+       supersede: Fix test failures on native Windows.
+       * lib/supersede.c (open_supersede): Handle non-regular files on native
+       Windows like on Solaris.
+       * tests/test-supersede-open.h (test_open_supersede): Use O_BINARY flag.
+
 2020-09-20  Paul Eggert  <eggert@cs.ucla.edu>
 
        test-stdalign: test Oracle Studio better
index a03cc6d13d39b1fbc0ffd5072b2a660839dd42ab..a3dfa4f93c1969ad7618f855542553cd1782cf8b 100644 (file)
@@ -80,10 +80,12 @@ open_supersede (const char *filename, int flags, mode_t mode,
   int fd;
   /* Extra flags for existing devices.  */
   int extra_flags =
-    #if defined __sun
+    #if defined __sun || (defined _WIN32 && !defined __CYGWIN__)
     /* open ("/dev/null", O_TRUNC | O_WRONLY) fails with error EINVAL on Solaris
-       zones.  See <https://www.illumos.org/issues/13035>.  As a workaround, add
-       the O_CREAT flag, although it ought not to be necessary.  */
+       zones.  See <https://www.illumos.org/issues/13035>.
+       Likewise for open ("NUL", O_TRUNC | O_RDWR) on native Windows.
+       As a workaround, add the O_CREAT flag, although it ought not to be
+       necessary.  */
     O_CREAT;
     #else
     0;
@@ -207,8 +209,8 @@ open_supersede (const char *filename, int flags, mode_t mode,
               action->final_rename_temp = NULL;
               action->final_rename_dest = NULL;
             }
-          #if defined __sun
-          /* Work around <https://www.illumos.org/issues/13035>.  */
+          #if defined __sun || (defined _WIN32 && !defined __CYGWIN__)
+          /* See the comment regarding extra_flags, above.  */
           else if (errno == EINVAL)
             {
               struct stat statbuf;
index f3b9b159f1d88848105f0868b0ea450aa3e853ff..74a56d80562bfba3e8fa941bf9e7d4323e067528 100644 (file)
@@ -30,7 +30,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
     ASSERT (stat (filename, &statbuf) < 0);
 
     struct supersede_final_action action;
-    int fd = open_supersede (filename, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (filename, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -56,7 +56,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
     ino_t orig_ino = statbuf.st_ino;
 
     struct supersede_final_action action;
-    int fd = open_supersede (filename, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (filename, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -101,7 +101,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
     ASSERT (stat (DEV_NULL, &statbuf) == 0);
 
     struct supersede_final_action action;
-    int fd = open_supersede (DEV_NULL, O_RDWR | O_TRUNC, 0666,
+    int fd = open_supersede (DEV_NULL, O_RDWR | O_BINARY | O_TRUNC, 0666,
                              supersede_if_exists, supersede_if_does_not_exist,
                              &action);
     ASSERT (fd >= 0);
@@ -125,7 +125,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -180,7 +180,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -209,7 +209,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd >= 0);
@@ -243,7 +243,7 @@ test_open_supersede (bool supersede_if_exists, bool supersede_if_does_not_exist)
 
         struct supersede_final_action action;
         int fd =
-          open_supersede (linkname, O_RDWR | O_TRUNC, 0666,
+          open_supersede (linkname, O_RDWR | O_BINARY | O_TRUNC, 0666,
                           supersede_if_exists, supersede_if_does_not_exist,
                           &action);
         ASSERT (fd < 0);