From 9bb631f1e1861c63f38125fffb91081c98a1cfcc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 May 2018 08:29:45 +0200 Subject: Add/remove/list binds, saving to file --- src/FileUtil.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/FileUtil.cpp') 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); + } } -- cgit v1.2.3