summaryrefslogtreecommitdiff
path: root/src/File.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
commit048a2cf59737f761876e81a77e8d064c45c752d7 (patch)
tree65c9d5498aafe6a8c8e640ddfcc43c7013504d0d /src/File.cc
parente26bbbb9eee140ba24402fe872a752b42f0077de (diff)
2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented BitTorrent/http/ftp integrated download. I've rewritten lots of files and now some headers have forward class declarations to reduce compile time. The implementation is extremely alpha stage, I recommend to use this for testing purpose only.
Diffstat (limited to 'src/File.cc')
-rw-r--r--src/File.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/File.cc b/src/File.cc
index 342b91ca..0796e1e0 100644
--- a/src/File.cc
+++ b/src/File.cc
@@ -37,6 +37,11 @@
#include "a2io.h"
#include <libgen.h>
+#ifdef __MINGW32__
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif // __MINGW32__
+
File::File(const string& name):name(name) {}
File::~File() {}
@@ -140,3 +145,21 @@ bool File::isDir(const string& filename)
{
return File(filename).isDir();
}
+
+bool File::renameTo(const string& dest)
+{
+#ifdef __MINGW32__
+ /* MinGW's rename() doesn't delete an existing destination */
+ if (_access(dest.c_str(), 0) == 0) {
+ if (_unlink(dest.c_str()) != 0) {
+ return false;
+ }
+ }
+#endif // __MINGW32__
+ if(rename(name.c_str(), dest.c_str()) == 0) {
+ name = dest;
+ return true;
+ } else {
+ return false;
+ }
+}