diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-04 21:57:32 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-04 21:57:32 +0300 |
commit | 8a5603e487f682f5f67bc2cedae81249aa138f5b (patch) | |
tree | 697535ca4d8e50ee6da8cf364cad814fa5f7603a /src/utils/files.cpp | |
parent | 80f7177ea4ce0185e1ef3355e91dcf14617d0f09 (diff) | |
parent | f2d1d2b43a0ebdb625aea94cb4b8ff7fce6bf8f4 (diff) | |
download | plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.gz plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.bz2 plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.xz plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.zip |
Merge branch 'master' into stable
Diffstat (limited to 'src/utils/files.cpp')
-rw-r--r-- | src/utils/files.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/utils/files.cpp b/src/utils/files.cpp index cb43ff5df..206a4d4bd 100644 --- a/src/utils/files.cpp +++ b/src/utils/files.cpp @@ -1,6 +1,6 @@ /* * The ManaPlus Client - * Copyright (C) 2013 The ManaPlus Developers + * Copyright (C) 2013-2014 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -126,6 +126,7 @@ void Files::extractZip(const std::string &restrict zipName, int Files::renameFile(const std::string &restrict srcName, const std::string &restrict dstName) { +#if defined __native_client__ FILE *srcFile = fopen(srcName.c_str(), "rb"); if (srcFile == nullptr) return -1; @@ -158,4 +159,40 @@ int Files::renameFile(const std::string &restrict srcName, return 0; return -1; +#else + 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; } |