]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/osx/dir_location.cpp
Use Core Foundation to discover standard locations on OS X
[libs/core.git] / source / fs / osx / dir_location.cpp
diff --git a/source/fs/osx/dir_location.cpp b/source/fs/osx/dir_location.cpp
new file mode 100644 (file)
index 0000000..7ce89f7
--- /dev/null
@@ -0,0 +1,35 @@
+#include "dir.h"
+
+using namespace std;
+
+extern "C" unsigned get_home_dir(char *, unsigned);
+extern "C" unsigned get_application_support_dir(char *, unsigned);
+
+namespace Msp {
+namespace FS {
+
+Path get_home_dir()
+{
+       char buf[1024];
+       unsigned len = ::get_home_dir(buf, sizeof(buf));
+       if(len)
+               return string(buf, len);
+
+       const char *home = getenv("HOME");
+       if(home)
+               return home;
+
+       return ".";
+}
+
+Path get_user_data_dir(const string &appname)
+{
+       char buf[1024];
+       unsigned len = get_application_support_dir(buf, sizeof(buf));
+       if(len)
+               return Path(string(buf, len))/appname;
+       return get_home_dir()/"Library"/"Application Support"/appname;
+}
+
+} // namespace FS
+} // namespace Msp