]> git.tdb.fi Git - libs/core.git/blob - source/fs/osx/dir_location.cpp
Fix references to deprecated functions
[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(const string &)
27 {
28         return get_user_data_dir();
29 }
30
31 Path get_user_data_dir()
32 {
33         const string &appname = Application::get_name();
34         if(appname.empty())
35                 throw logic_error("no application name");
36
37         char buf[1024];
38         unsigned len = get_application_support_dir(buf, sizeof(buf));
39         if(len)
40                 return Path(string(buf, len))/appname;
41         return get_home_dir()/"Library"/"Application Support"/appname;
42 }
43
44 } // namespace FS
45 } // namespace Msp