aboutsummaryrefslogtreecommitdiff
path: root/src/FileUtil.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-03 08:29:45 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-03 08:29:48 +0200
commit9bb631f1e1861c63f38125fffb91081c98a1cfcc (patch)
treead852904b8ae278c789e7f636ed4107038231c3f /src/FileUtil.cpp
parent9cde35c64c9f569055b101a80419d900f58806a9 (diff)
Add/remove/list binds, saving to file
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r--src/FileUtil.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp
index 53687dd..c2746ed 100644
--- a/src/FileUtil.cpp
+++ b/src/FileUtil.cpp
@@ -32,4 +32,26 @@ namespace dchat
fclose(file);
return { fileData, fileSize };
}
+
+ void fileReplace(const boost::filesystem::path &filepath, const StringView 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 replace file: ";
+ errMsg += filepath.string();
+ errMsg += ", reason: ";
+ errMsg += strerror(error);
+ throw FileException(errMsg);
+ }
+
+ setbuf(file, NULL);
+ fwrite(data.data, 1, data.size, file);
+ fclose(file);
+ }
}