]> git.tdb.fi Git - libs/core.git/blob - source/fs/unix/dir.cpp
93aaeab5c73339e668af52e2f077e36839b98bbe
[libs/core.git] / source / fs / unix / dir.cpp
1 #include <cstdlib>
2 #include <unistd.h>
3 #include <sys/stat.h>
4 #include <msp/core/systemerror.h>
5 #include "dir.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace FS {
11
12 void mkdir(const Path &path, int mode)
13 {
14         if(::mkdir(path.str().c_str(), mode)==-1)
15                 throw system_error("mkdir");
16 }
17
18 void rmdir(const Path &path)
19 {
20         if(::rmdir(path.str().c_str())==-1)
21                 throw system_error("rmdir");
22 }
23
24 Path get_home_dir()
25 {
26         const char *home = getenv("HOME");
27         if(home)
28                 return home;
29         return ".";
30 }
31
32 Path get_user_data_dir(const string &appname)
33 {
34         return get_home_dir()/("."+appname);
35 }
36
37 } // namespace FS
38 } // namespace Msp