aboutsummaryrefslogtreecommitdiff
path: root/src/FileUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r--src/FileUtil.cpp27
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);
+ }
}