summaryrefslogtreecommitdiff
path: root/src/utils/files.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-01 13:17:34 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-01 13:17:34 +0300
commitc28e2e8e0cfa0ae4358f798c3bd34c8678de9541 (patch)
treedb84a006ab6e2a8d4d00a25e8216ed22ac6d2fb9 /src/utils/files.cpp
parent9fc83299bfb029328f19671efae42a7f4b4d465a (diff)
downloadplus-c28e2e8e0cfa0ae4358f798c3bd34c8678de9541.tar.gz
plus-c28e2e8e0cfa0ae4358f798c3bd34c8678de9541.tar.bz2
plus-c28e2e8e0cfa0ae4358f798c3bd34c8678de9541.tar.xz
plus-c28e2e8e0cfa0ae4358f798c3bd34c8678de9541.zip
add ability for auto backup main configuration file on startup.
Diffstat (limited to 'src/utils/files.cpp')
-rw-r--r--src/utils/files.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index 216a83991..40a4da757 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -163,3 +163,36 @@ int Files::renameFile(const std::string &restrict srcName,
return ::rename(srcName.c_str(), dstName.c_str());
#endif
}
+
+int Files::copyFile(const std::string &restrict srcName,
+ const std::string &restrict dstName)
+{
+ FILE *srcFile = fopen(srcName.c_str(), "rb");
+ if (srcFile == nullptr)
+ return -1;
+ FILE *dstFile = fopen(dstName.c_str(), "w+b");
+ if (dstFile == nullptr)
+ {
+ fclose(srcFile);
+ return -1;
+ }
+
+ const int chunkSize = 500000;
+ char *buf = new char[chunkSize];
+ size_t sz = 0;
+ while ((sz = fread(buf, 1, chunkSize, srcFile)))
+ {
+ if (fwrite(buf, 1, sz, dstFile) != sz)
+ {
+ delete [] buf;
+ fclose(srcFile);
+ fclose(dstFile);
+ return -1;
+ }
+ }
+
+ delete [] buf;
+ fclose(srcFile);
+ fclose(dstFile);
+ return 0;
+}