io/FileOutputStream: use fsync() if fdatasync() is unavailable

Fixes the macOS build which apparently doesn't implement the POSIX
function fdatasync().
This commit is contained in:
Max Kellermann 2022-07-14 18:31:58 +02:00
parent bc7fdba36d
commit 150e8f78bf

View File

@ -252,7 +252,12 @@ FileOutputStream::Sync()
{
assert(IsDefined());
if (fdatasync(fd.Get()) < 0)
#ifdef __linux__
const bool success = fdatasync(fd.Get()) == 0;
#else
const bool success = fsync(fd.Get()) == 0;
#endif
if (!success)
throw FormatErrno("Failed to sync %s", GetPath().c_str());
}