From 3fcdcac504be1e4d55cbee0fa185b380712545d7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 21 Sep 2020 00:51:54 +0200 Subject: [PATCH] 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. --- ChangeLog | 7 +++++++ lib/supersede.c | 12 +++++++----- tests/test-supersede-open.h | 14 +++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7a0ce8403..167c7e7893 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2020-09-20 Bruno Haible + + 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 test-stdalign: test Oracle Studio better diff --git a/lib/supersede.c b/lib/supersede.c index a03cc6d13d..a3dfa4f93c 100644 --- a/lib/supersede.c +++ b/lib/supersede.c @@ -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 . As a workaround, add - the O_CREAT flag, although it ought not to be necessary. */ + zones. See . + 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 . */ + #if defined __sun || (defined _WIN32 && !defined __CYGWIN__) + /* See the comment regarding extra_flags, above. */ else if (errno == EINVAL) { struct stat statbuf; diff --git a/tests/test-supersede-open.h b/tests/test-supersede-open.h index f3b9b159f1..74a56d8056 100644 --- a/tests/test-supersede-open.h +++ b/tests/test-supersede-open.h @@ -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); -- 2.11.4.GIT