]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/unix/dir.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / fs / unix / dir.cpp
diff --git a/source/fs/unix/dir.cpp b/source/fs/unix/dir.cpp
new file mode 100644 (file)
index 0000000..93aaeab
--- /dev/null
@@ -0,0 +1,38 @@
+#include <cstdlib>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <msp/core/systemerror.h>
+#include "dir.h"
+
+using namespace std;
+
+namespace Msp {
+namespace FS {
+
+void mkdir(const Path &path, int mode)
+{
+       if(::mkdir(path.str().c_str(), mode)==-1)
+               throw system_error("mkdir");
+}
+
+void rmdir(const Path &path)
+{
+       if(::rmdir(path.str().c_str())==-1)
+               throw system_error("rmdir");
+}
+
+Path get_home_dir()
+{
+       const char *home = getenv("HOME");
+       if(home)
+               return home;
+       return ".";
+}
+
+Path get_user_data_dir(const string &appname)
+{
+       return get_home_dir()/("."+appname);
+}
+
+} // namespace FS
+} // namespace Msp