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