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 }