summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2020-05-05 20:35:25 -0700
committerMark Adler <madler@alumni.caltech.edu>2020-05-05 20:35:25 -0700
commit37ebc02f3220a6bbd0b8b320499ed84a94246e55 (patch)
treea1d5bd871198d68c40135477188ec0ac6b23fa8c
parent539a329bd5c0806e5f1d010910cc938bf661fb4f (diff)
downloadpigz-37ebc02f3220a6bbd0b8b320499ed84a94246e55.tar.gz
Use _commit on Windows for --synchronous (-Y) option.
-rw-r--r--pigz.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/pigz.c b/pigz.c
index 9dce538..5efea61 100644
--- a/pigz.c
+++ b/pigz.c
@@ -418,8 +418,8 @@
#define local static
// Prevent end-of-line conversions on MSDOSish operating systems.
-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-# include <io.h> // setmode(), O_BINARY
+#if defined(MSDOS) || defined(OS2) || defined(_WIN32) || defined(__CYGWIN__)
+# include <io.h> // setmode(), O_BINARY, _commit() for _WIN32
# define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
#else
# define SET_BINARY_MODE(fd)
@@ -3836,16 +3836,14 @@ local void touch(char *path, time_t t) {
// memory on the device itself, leaving open a window of vulnerability.
// fcntl(fd, F_FULLSYNC) on the other hand, available in macOS only, will
// request and wait for the device to write out its buffered data to permanent
-// storage.
-//
-// For a future Windows port of pigz, winbase.h should be included and
-// FlushFileBuffers() used, which also waits for the device write out its
-// buffered data to permanent storage.
+// storage. On Windows, _commit() is used.
local void out_push(void) {
if (g.outd == -1)
return;
-#ifdef F_FULLSYNC
+#if defined(F_FULLSYNC)
int ret = fcntl(g.outd, F_FULLSYNC);
+#elif defined(_WIN32)
+ int ret = _commit(g.outd);
#else
int ret = fsync(g.outd);
#endif