From 2b2d5d6b218cdf05d49893056891eb81719a43f7 Mon Sep 17 00:00:00 2001 From: Marko Radmilac Date: Thu, 28 Jan 2016 11:39:18 -0800 Subject: [PATCH] Add Windows flavor of file sync --- Source/Common/fileutil.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/Common/fileutil.cpp b/Source/Common/fileutil.cpp index 7bea7f00d..4f7af3fd1 100644 --- a/Source/Common/fileutil.cpp +++ b/Source/Common/fileutil.cpp @@ -419,7 +419,6 @@ void fflushOrDie(FILE* f) RuntimeError("error flushing to file: %s", strerror(errno)); } -#ifndef _WIN32 int fd = fileno(f); if (fd == -1) @@ -428,7 +427,18 @@ void fflushOrDie(FILE* f) } // Ensure that all data is synced before returning from this function - fsync(fd); +#ifdef _WIN32 + if (!FlushFileBuffers((HANDLE)_get_osfhandle(fd))) + { + RuntimeError("error syncing to file: %d", (int) ::GetLastError()); + } +#else + rc = fsync(fd); + + if (rc != 0) + { + RuntimeError("error syncing to file: %s", strerror(errno)); + } #endif }