]> git.tdb.fi Git - libs/core.git/blob - source/fs/osx/dir_location.cpp
Add move semantics to Variant
[libs/core.git] / source / fs / osx / dir_location.cpp
1 #include <msp/core/application.h>
2 #include <msp/core/environ.h>
3 #include <msp/core/except.h>
4 #include "dir.h"
5
6 using namespace std;
7
8 extern "C" unsigned get_home_dir(char *, unsigned);
9 extern "C" unsigned get_application_support_dir(char *, unsigned);
10
11 namespace Msp {
12 namespace FS {
13
14 Path get_home_dir()
15 {
16         char buf[1024];
17         unsigned len = ::get_home_dir(buf, sizeof(buf));
18         if(len)
19                 return string(buf, len);
20
21         string home = getenv("HOME");
22         if(!home.empty())
23                 return home;
24
25         return ".";
26 }
27
28 Path get_user_data_dir()
29 {
30         const string &appname = Application::get_name();
31         if(appname.empty())
32                 throw invalid_state("no application name");
33
34         char buf[1024];
35         unsigned len = get_application_support_dir(buf, sizeof(buf));
36         if(len)
37                 return Path(string(buf, len))/appname;
38         return get_home_dir()/"Library"/"Application Support"/appname;
39 }
40
41 } // namespace FS
42 } // namespace Msp