diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-10-05 05:02:49 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-06 07:39:33 +0200 |
commit | 5250cb90406693163763a214af95f670e0e3a4e0 (patch) | |
tree | 7025c762d4f53aebfdc140d615306f558fa9b69a /src/FileUtil.cpp | |
parent | 3059b1cb8d701cf23f3e04a8a8fdcfcaa6a397fb (diff) |
Add cross compilation (mingw-w64 x86_64)
Currently only cross compiling from linux64 to win64 works.
Need to test cross compilation more, currently the cross compilation
uses same profile as GCC, is that correct?
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r-- | src/FileUtil.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 498f638..e317304 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -1,5 +1,6 @@ #include "../include/FileUtil.hpp" #include <cstdio> +#include <fstream> #if OS_FAMILY == OS_FAMILY_POSIX #include <unistd.h> @@ -497,4 +498,30 @@ namespace sibs return pathIndex == path.size() && otherPathIndex == otherPath.size(); } + + Result<bool> copyFile(const FileString &src, const FileString &dst) + { + ifstream srcFile(src.c_str(), ios::binary); + if(!srcFile) + { + string errMsg = "Failed to open file "; + errMsg += toUtf8(src); + errMsg += ", reason: "; + errMsg += strerror(errno); + return Result<bool>::Err(errMsg); + } + + ofstream dstFile(dst.c_str(), ios::binary); + if(!dstFile) + { + string errMsg = "Failed to create/overwrite file "; + errMsg += toUtf8(dst); + errMsg += ", reason: "; + errMsg += strerror(errno); + return Result<bool>::Err(errMsg); + } + + dstFile << srcFile.rdbuf(); + return Result<bool>::Ok(true); + } } |