macOS: checking Fl_Preferences file path improved

zlib: removed warning
This commit is contained in:
Matthias Melcher 2020-01-03 17:05:52 +01:00
parent db6fa8bf86
commit 8147199a41
4 changed files with 45 additions and 24 deletions

View File

@ -923,7 +923,7 @@ Fl_Preferences::RootNode::~RootNode() {
// read a preferences file and construct the group tree and with all entry leafs
int Fl_Preferences::RootNode::read() {
if (!filename_) // RUNTIME preferences
if (!filename_) // RUNTIME preferences, or filename could not be created
return -1;
if ( (root_ & Fl_Preferences::CORE) && !(fileAccess_ & Fl_Preferences::CORE_READ_OK) ) {
prefs_->node->clearDirtyFlags();
@ -972,7 +972,7 @@ int Fl_Preferences::RootNode::read() {
// write the group tree and all entry leafs
int Fl_Preferences::RootNode::write() {
if (!filename_) // RUNTIME preferences
if (!filename_) // RUNTIME preferences, or filename could not be created
return -1;
if ( (root_ & Fl_Preferences::CORE) && !(fileAccess_ & Fl_Preferences::CORE_WRITE_OK) )
return -1;
@ -1010,7 +1010,7 @@ int Fl_Preferences::RootNode::write() {
// - copy the path into the buffer at "path"
// - if the resulting path is longer than "pathlen", it will be cropped
char Fl_Preferences::RootNode::getPath( char *path, int pathlen ) {
if (!filename_) // RUNTIME preferences
if (!filename_) // RUNTIME preferences. or filename could not be created
return 1; // return 1 (not -1) to be consistent with fl_make_path()
if (pathlen<=0)

View File

@ -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$".
//

View File

@ -242,26 +242,6 @@ void Fl_Darwin_System_Driver::newUUID(char *uuidBuffer)
CFRelease(theUUID);
}
char *Fl_Darwin_System_Driver::preference_rootnode(Fl_Preferences *prefs, Fl_Preferences::Root root,
const char *vendor, const char *application)
{
static char filename[ FL_PATH_MAX ];
// TODO: verify that this is the Apple sanctioned way of finding these folders
// (On Windows, this frequently leads to issues with internationalized systems)
// Carbon: err = FindFolder( kLocalDomain, kPreferencesFolderType, 1, &spec.vRefNum, &spec.parID );
switch (root&Fl_Preferences::ROOT_MASK) {
case Fl_Preferences::SYSTEM:
strcpy(filename, "/Library/Preferences");
break;
case Fl_Preferences::USER:
sprintf(filename, "%s/Library/Preferences", getenv("HOME"));
break;
}
snprintf(filename + strlen(filename), sizeof(filename) - strlen(filename),
"/%s/%s.prefs", vendor, application);
return filename;
}
/*
* returns pointer to the filename, or null if name ends with ':'
*/

View File

@ -1504,7 +1504,8 @@ z_streamp strm;
{
struct inflate_state FAR *state;
if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16;
if (strm == Z_NULL || strm->state == Z_NULL)
return ((unsigned)-1L) << 16;
state = (struct inflate_state FAR *)strm->state;
return ((long)(state->back) << 16) +
(state->mode == COPY ? state->length :