util: fix WriteBinaryFile() claiming success even if error occurred

`fclose()` is flushing any buffered data to disk, so if it fails then
that could mean that the data was not completely written to disk.

Thus, check if `fclose()` succeeds and only then claim success from
`WriteBinaryFile()`.
This commit is contained in:
Vasil Dimov 2020-11-18 17:38:43 +01:00
parent 8b6e4b3b23
commit 545bc5f81d
No known key found for this signature in database
GPG Key ID: 54DF06F64B55CBBF

View File

@ -40,6 +40,8 @@ bool WriteBinaryFile(const fs::path &filename, const std::string &data)
fclose(f);
return false;
}
fclose(f);
if (fclose(f) != 0) {
return false;
}
return true;
}