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