Properly check for fdatasync()

This commit is contained in:
benrubson 2017-06-01 15:41:37 +02:00
parent 11a83b85ba
commit af6c593b38
3 changed files with 11 additions and 5 deletions

View File

@ -93,6 +93,12 @@ check_cxx_source_compiles ("#include <sys/types.h>
" XATTR_ADD_OPT)
set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
# Check if we have fdatasync.
include (CheckCXXSourceCompiles)
check_cxx_source_compiles ("#include <unistd.h>
int main() { fdatasync(0); return 1; }
" FDATASYNC)
# Check if we have some standard functions.
include (CheckFuncs)
check_function_exists_glibc (lchmod HAVE_LCHMOD)

View File

@ -236,15 +236,13 @@ int FileNode::sync(bool datasync) {
int fh = io->open(O_RDONLY);
if (fh >= 0) {
int res = -EIO;
#ifdef linux
#ifdef FDATASYNC
if (datasync)
res = fdatasync(fh);
else
res = fsync(fh);
#else
(void)datasync;
// no fdatasync support
// TODO: use autoconfig to check for it..
res = fsync(fh);
#endif

View File

@ -270,11 +270,13 @@ int RawFileIO::truncate(off_t size) {
knownSize = true;
}
#if !defined(__FreeBSD__) && !defined(__APPLE__)
if (fd >= 0 && canWrite) {
#ifdef FDATASYNC
::fdatasync(fd);
}
#else
::fsync(fd);
#endif
}
return res;
}