From 64b635de88d64a3650136182d7a584aece103e15 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 9 Jul 2012 17:45:17 +0300 Subject: [PATCH 1/1] Use native CreateDirectory/RemoveDirectory calls on Windows --- source/fs/dir.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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) -- 2.43.0