diff options
Diffstat (limited to 'src/FileUtils.cpp')
-rw-r--r-- | src/FileUtils.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 6dc10b8..c4fb318 100644 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -55,4 +55,27 @@ namespace odhtdb fwrite(data.data, 1, data.size, file); fclose(file); } + + void fileOverwrite(const boost::filesystem::path &filepath, const DataView &data) + { +#if OS_FAMILY == OS_FAMILY_POSIX + FILE *file = fopen(filepath.string().c_str(), "wb+"); +#else + FILE *file = _wfopen(filepath.wstring().c_str(), L"wb+"); +#endif + if(!file) + { + int error = errno; + string errMsg = "Failed to overwrite file: "; + errMsg += filepath.string(); + errMsg += "; reason: "; + errMsg += strerror(error); + throw FileException(errMsg); + } + + flockfile(file); + setbuf(file, NULL); + fwrite(data.data, 1, data.size, file); + fclose(file); + } } |