Skip to content

Commit

Permalink
Add Windows flavor of file sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Radmilac committed Jan 28, 2016
1 parent 4c7919a commit 2b2d5d6
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/Common/fileutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 2b2d5d6

Please sign in to comment.