diff options
author | dec05eba <0xdec05eba@gmail.com> | 2018-05-15 06:06:02 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-05-15 06:06:06 +0200 |
commit | 4b656c5600a28f05665e849715af3d08f29dff2f (patch) | |
tree | 88c96a5f90c52fbc5f1670f607a7dcbf63fd9659 /src/FileUtils.cpp | |
parent | 4a0d1ff39ec150d8e8c04ca846b3116884e1774e (diff) |
Store known remote nodes and connect to them next time
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); + } } |