Skip to content

Commit

Permalink
FileCommit() Fixed
Browse files Browse the repository at this point in the history
fcntl() with F_FULLFSYNC returns 0 on success or -1 on failure
  • Loading branch information
ghostlander committed Dec 20, 2021
1 parent 67734dc commit a2759e7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1085,13 +1085,14 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
#endif /* WINDOWS */
}

/* Returns zero on success and -1 on failure */
/* Syncronises a file with a medium;
* returns zero on success or -1 on failure */
int FileCommit(FILE *fileout) {
int ret, fd;

/* fflush() is a caller's responsibility */
/* fflush() is a caller's responsibility;
* get a file descriptor first and perform the synchronisation next */

/* Get a file descriptor and perform the synchronisation */
#if (WINDOWS)
fd = _fileno(fileout);
ret = _commit(fd);
Expand All @@ -1100,10 +1101,10 @@ int FileCommit(FILE *fileout) {
#if (__linux__)
ret = fdatasync(fd);
#elif (__APPLE__) && (F_FULLFSYNC)
/* F_FULLFSYNC means fsync with device flush to medium;
* works with HFS only as of 10.4, so fail over to fsync */
/* fcntl() with F_FULLFSYNC means fsync() with device flush to medium;
* works with HFS only as of 10.4, so fail over to fsync() */
ret = fcntl(fd, F_FULLFSYNC, 0);
if(!ret) ret = fsync(fd);
if(ret) ret = fsync(fd);
#else
ret = fsync(fd);
#endif
Expand Down

0 comments on commit a2759e7

Please sign in to comment.