]> git.tdb.fi Git - libs/core.git/blob - source/fs/unix/dir.cpp
8169a63fffbe9809af24012ed4ae28101ac881e3
[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 getcwd()
25 {
26         char buf[1024];
27         return ::getcwd(buf, sizeof(buf));
28 }
29
30 void chdir(const Path &path)
31 {
32         if(::chdir(path.str().c_str())==-1)
33                 throw system_error("chdir");
34 }
35
36 Path get_home_dir()
37 {
38         const char *home = getenv("HOME");
39         if(home)
40                 return home;
41         return ".";
42 }
43
44 Path get_user_data_dir(const string &appname)
45 {
46         if(appname.empty())
47                 throw invalid_argument("get_user_data_dir");
48         return get_home_dir()/("."+appname);
49 }
50
51 } // namespace FS
52 } // namespace Msp