From: Mikko Rasa Date: Mon, 9 Jul 2012 14:45:17 +0000 (+0300) Subject: Use native CreateDirectory/RemoveDirectory calls on Windows X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=64b635de88d64a3650136182d7a584aece103e15;p=libs%2Fcore.git Use native CreateDirectory/RemoveDirectory calls on Windows --- diff --git a/source/fs/dir.cpp b/source/fs/dir.cpp index 2575beb..ea0cd95 100644 --- a/source/fs/dir.cpp +++ b/source/fs/dir.cpp @@ -1,11 +1,11 @@ #include #include #include -#include #ifdef WIN32 #include #else #include +#include #endif #include #include @@ -64,17 +64,14 @@ not_a_directory::not_a_directory(const Path &p): void mkdir(const Path &path, int mode) { - int err; #ifdef WIN32 - // The win32 version of this function doesn't take the mode argument. Go figure. (void)mode; - err = ::mkdir(path.str().c_str()); + if(!CreateDirectory(path.str().c_str(), NULL)) + throw system_error("CreateDirectory"); #else - err = ::mkdir(path.str().c_str(), mode); -#endif - - if(err==-1) + if(::mkdir(path.str().c_str(), mode)==-1) throw system_error("mkdir"); +#endif } void mkpath(const Path &path, int mode) @@ -100,8 +97,13 @@ void mkpath(const Path &path, int mode) void rmdir(const Path &path) { +#ifdef WIN32 + if(!RemoveDirectory(path.str().c_str())) + throw system_error("RemoveDirectory"); +#else if(::rmdir(path.str().c_str())==-1) throw system_error("rmdir"); +#endif } void rmpath(const Path &path)