From 4b656c5600a28f05665e849715af3d08f29dff2f Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 15 May 2018 06:06:02 +0200 Subject: Store known remote nodes and connect to them next time --- src/FileUtils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/FileUtils.cpp') 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); + } } -- cgit v1.2.3