diff options
author | Dan Sagunov <danilka.pro@gmail.com> | 2013-11-02 00:01:15 +0400 |
---|---|---|
committer | Dan Sagunov <danilka.pro@gmail.com> | 2013-11-02 00:01:15 +0400 |
commit | c2f7ae98d3c321a615cda6946443f5098d9d08bd (patch) | |
tree | b330c943055f7b299b4dd9ea64a440e8be9e94e7 /src/utils/files.cpp | |
parent | dd380bf0c3ed3150e57bf4b14d51cae1c206565e (diff) | |
download | mv-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.gz mv-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.bz2 mv-c2f7ae98d3c321a615cda6946443f5098d9d08bd.tar.xz mv-c2f7ae98d3c321a615cda6946443f5098d9d08bd.zip |
Adding renameFile function for NaCl
Diffstat (limited to 'src/utils/files.cpp')
-rw-r--r-- | src/utils/files.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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__ |