]> 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 "dir.h"
4
5 using namespace std;
6
7 extern "C" unsigned get_home_dir(char *, unsigned);
8 extern "C" unsigned get_application_support_dir(char *, unsigned);
9
10 namespace Msp {
11 namespace FS {
12
13 Path get_home_dir()
14 {
15         char buf[1024];
16         unsigned len = ::get_home_dir(buf, sizeof(buf));
17         if(len)
18                 return string(buf, len);
19
20         string home = getenv("HOME");
21         if(!home.empty())
22                 return home;
23
24         return ".";
25 }
26
27 Path get_user_data_dir()
28 {
29         const string &appname = Application::get_name();
30         if(appname.empty())
31                 throw logic_error("no application name");
32
33         char buf[1024];
34         unsigned len = get_application_support_dir(buf, sizeof(buf));
35         if(len)
36                 return Path(string(buf, len))/appname;
37         return get_home_dir()/"Library"/"Application Support"/appname;
38 }
39
40 } // namespace FS
41 } // namespace Msp