#include <cstdlib>
#include <cerrno>
#include <dirent.h>
-#include <sys/stat.h>
#ifdef WIN32
#include <shlobj.h>
#else
#include <unistd.h>
+#include <sys/stat.h>
#endif
#include <msp/core/systemerror.h>
#include <msp/strings/regex.h>
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)
if(p.size()==1 && p.is_absolute())
continue;
#endif
- if(exists(p))
+ if(FS::Stat st = stat(p))
{
- if(!is_dir(p))
+ if(!st.is_directory())
throw not_a_directory(p);
continue;
}
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)