summaryrefslogtreecommitdiff
path: root/src/Fl_cocoa.mm
diff options
context:
space:
mode:
authorMatthias Melcher <git@matthiasm.com>2020-01-03 17:05:52 +0100
committerMatthias Melcher <git@matthiasm.com>2020-01-03 17:05:52 +0100
commit8147199a41e8cc39b0268433916dfccfcfc8e6eb (patch)
treec2261f81fc5c22b25644cc9e1abc366bee49e837 /src/Fl_cocoa.mm
parentdb6fa8bf86407a0d1a1de180fff55702e1f75d6f (diff)
macOS: checking Fl_Preferences file path improved
zlib: removed warning
Diffstat (limited to 'src/Fl_cocoa.mm')
-rw-r--r--src/Fl_cocoa.mm40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index b0a13d714..80022fdd4 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -4387,6 +4387,46 @@ int Fl_Darwin_System_Driver::calc_mac_os_version() {
return fl_mac_os_version;
}
+char *Fl_Darwin_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root,
+ const char *vendor, const char *application)
+{
+ static char *filename = 0L;
+
+ // Allocate this only when we need it, but then keep it allocated.
+ if (!filename) filename = (char*)::calloc(1, FL_PATH_MAX);
+
+ switch (root&Fl_Preferences::ROOT_MASK) {
+ case Fl_Preferences::SYSTEM:
+ // This is safe, even on machines that use different languages
+ strcpy(filename, "/Library/Preferences");
+ break;
+ case Fl_Preferences::USER:
+ { // Find the home directory, but return NULL if components were not found.
+ // If we ever port this to iOS: this returns tha location of the app!
+ NSString *nsHome = NSHomeDirectory();
+ if (!nsHome) return 0L;
+ const char *cHome = [nsHome UTF8String];
+ if (!cHome) return 0L;
+ snprintf(filename, FL_PATH_MAX, "%s/Library/Preferences", cHome);
+ break; }
+ }
+
+ // Make sure that the parameters are not NULL
+ if ( (vendor==0L) || (vendor[0]==0) )
+ vendor = "unknown";
+ if ( (application==0L) || (application[0]==0) )
+ application = "unknown";
+
+ // Our C path names for preferences will be:
+ // SYSTEM: "/Library/Preferences/$vendor/$application.prefs"
+ // SYSTEM: "/Users/$user/Preferences/$vendor/$application.prefs"
+ snprintf(filename + strlen(filename), FL_PATH_MAX - strlen(filename),
+ "/%s/%s.prefs", vendor, application);
+
+ return filename;
+}
+
+
//
// End of "$Id$".
//