aboutsummaryrefslogtreecommitdiff
path: root/src/FileUtils.cpp
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-15 06:06:02 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-15 06:06:06 +0200
commit4b656c5600a28f05665e849715af3d08f29dff2f (patch)
tree88c96a5f90c52fbc5f1670f607a7dcbf63fd9659 /src/FileUtils.cpp
parent4a0d1ff39ec150d8e8c04ca846b3116884e1774e (diff)
Store known remote nodes and connect to them next time
Diffstat (limited to 'src/FileUtils.cpp')
-rw-r--r--src/FileUtils.cpp23
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);
+ }
}