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;
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;
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);
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);
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);
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);
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);
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);
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);