diff options
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r-- | src/FileUtil.cpp | 22 |
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); + } } |