summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sagunov <danilka.pro@gmail.com>2013-11-02 00:01:15 +0400
committerDan Sagunov <danilka.pro@gmail.com>2013-11-02 00:01:15 +0400
commitc2f7ae98d3c321a615cda6946443f5098d9d08bd (patch)
treeb330c943055f7b299b4dd9ea64a440e8be9e94e7
parentdd380bf0c3ed3150e57bf4b14d51cae1c206565e (diff)
downloadplus-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.gz
plus-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.bz2
plus-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.xz
plus-c2f7ae98d3c321a615cda6946443f5098d9d08bd.zip
Adding renameFile function for NaCl
-rw-r--r--src/net/download.cpp11
-rw-r--r--src/utils/files.cpp29
-rw-r--r--src/utils/files.h2
3 files changed, 41 insertions, 1 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 3ccff63c8..38b8d2873 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -39,6 +39,10 @@
((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && \
(LIBCURL_VERSION_PATCH >= (c))))
+#if defined __native_client__
+#include "utils/files.h"
+#endif
+
#include "debug.h"
const char *DOWNLOAD_ERROR_MESSAGE_THREAD
@@ -360,7 +364,12 @@ int Download::downloadThread(void *ptr)
if (!d->mOptions.cancel)
{
::remove(d->mFileName.c_str());
- ::rename(outFilename.c_str(), d->mFileName.c_str());
+#if defined __native_client__
+ Files::renameFile(
+#else
+ ::rename(
+#endif
+ outFilename.c_str(), d->mFileName.c_str());
// Check if we can open it and no errors were encountered
// during renaming
diff --git a/src/utils/files.cpp b/src/utils/files.cpp
index c06b3d892..fa69cd6af 100644
--- a/src/utils/files.cpp
+++ b/src/utils/files.cpp
@@ -100,4 +100,33 @@ void Files::extractZip(const std::string &zipName, const std::string &inDir,
remove(zipName.c_str());
}
+int Files::renameFile(const std::string &pFrom, const std::string &pTo)
+{
+ FILE *file = fopen(pFrom.c_str(), "rb");
+ if (file == NULL)
+ return -1;
+
+ fseek(file, 0, SEEK_END);
+ size_t sz = ftell(file);
+ fseek(file, 0, SEEK_SET);
+
+ char *buf = (char *)malloc(sz + 1);
+ if (fread(buf, 1, sz, file) != sz)
+ return -1;
+ fclose(file);
+ buf[sz] = 0;
+
+ file = fopen(pTo.c_str(), "w+b");
+ if (file == NULL)
+ return -1;
+
+ if (fwrite(buf, 1, sz, file) != sz)
+ return -1;
+ fclose(file);
+
+ free(buf);
+
+ return 0;
+}
+
#endif // ANDROID __native_client__
diff --git a/src/utils/files.h b/src/utils/files.h
index 519b7f520..4a44631cf 100644
--- a/src/utils/files.h
+++ b/src/utils/files.h
@@ -35,6 +35,8 @@ namespace Files
void extractZip(const std::string &zipName, const std::string &inDir,
const std::string &outDir);
+
+ int renameFile(const std::string &pFrom, const std::string &pTo);
} // namespace Files
#endif // ANDROID __native_client__