summaryrefslogtreecommitdiff
path: root/src/drivers/Darwin
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2022-01-19 16:08:29 +0100
committerGitHub <noreply@github.com>2022-01-19 16:08:29 +0100
commit09eff7243a6e8e37d9615df7b951ffa3c03c0ae2 (patch)
tree513b39c92f1f6a9d0f0ca7f9a1488f298f7a068e /src/drivers/Darwin
parent793f4b90fac349b096922a6b90ae2731777ac6cf (diff)
Fixing and upgrading Fl_Preferences (#374)
* Added filename function to Fl_Preferences Static function to get filename before opening. Member to get filename after opening. Bug fixes for memory mapped preferences. * ERROR is a macro on Windows, don't use it * Added Fl_Preferences::dirty(). User can now check if the database will be written when flushed or destroyed. Flush returns a crude error code. * Fl_Preferences::get binary data returns # of bytes read. * Verified group deletion code * Fl_Preferences ignores locale. This will make .prefs files interchangeable between different computers. * Updating the Preferences Mode to ignore locale. * Fixes in docs.
Diffstat (limited to 'src/drivers/Darwin')
-rw-r--r--src/drivers/Darwin/Fl_Darwin_System_Driver.H2
-rw-r--r--src/drivers/Darwin/Fl_Darwin_System_Driver.cxx38
2 files changed, 39 insertions, 1 deletions
diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.H b/src/drivers/Darwin/Fl_Darwin_System_Driver.H
index 7d076a9ce..8a2e3b7f6 100644
--- a/src/drivers/Darwin/Fl_Darwin_System_Driver.H
+++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.H
@@ -45,6 +45,8 @@ public:
virtual int single_arg(const char *arg);
virtual int arg_and_value(const char *name, const char *value);
virtual int clocale_printf(FILE *output, const char *format, va_list args);
+ virtual int clocale_snprintf(char *output, size_t output_size, const char *format, va_list args);
+ virtual int clocale_sscanf(const char *input, const char *format, va_list args);
static void *get_carbon_function(const char *name);
static int calc_mac_os_version(); // computes the fl_mac_os_version global variable
static unsigned short *compute_macKeyLookUp();
diff --git a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
index 511b3b048..dad46dfc7 100644
--- a/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
+++ b/src/drivers/Darwin/Fl_Darwin_System_Driver.cxx
@@ -116,10 +116,15 @@ int Fl_Darwin_System_Driver::arg_and_value(const char *name, const char *value)
return strcmp(name, "NSDocumentRevisionsDebugMode") == 0;
}
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+static locale_t postscript_locale = NULL;
+#endif
+
int Fl_Darwin_System_Driver::clocale_printf(FILE *output, const char *format, va_list args) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (fl_mac_os_version >= 100400) {
- static locale_t postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
+ if (!postscript_locale)
+ postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
return vfprintf_l(output, postscript_locale, format, args);
}
#endif
@@ -130,6 +135,37 @@ int Fl_Darwin_System_Driver::clocale_printf(FILE *output, const char *format, va
return retval;
}
+int Fl_Darwin_System_Driver::clocale_snprintf(char *output, size_t output_size, const char *format, va_list args) {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if (fl_mac_os_version >= 100400) {
+ if (!postscript_locale)
+ postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
+ return vsnprintf_l(output, output_size, postscript_locale, format, args);
+ }
+#endif
+ char *saved_locale = setlocale(LC_NUMERIC, NULL);
+ setlocale(LC_NUMERIC, "C");
+ int retval = vsnprintf(output, output_size, format, args);
+ setlocale(LC_NUMERIC, saved_locale);
+ return retval;
+}
+
+int Fl_Darwin_System_Driver::clocale_sscanf(const char *input, const char *format, va_list args) {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
+ if (fl_mac_os_version >= 100400) {
+ if (!postscript_locale)
+ postscript_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
+ return vsscanf_l(input, postscript_locale, format, args);
+ }
+#endif
+ char *saved_locale = setlocale(LC_NUMERIC, NULL);
+ setlocale(LC_NUMERIC, "C");
+ int retval = vsscanf(input, format, args);
+ setlocale(LC_NUMERIC, saved_locale);
+ return retval;
+}
+
+
/* Returns the address of a Carbon function after dynamically loading the Carbon library if needed.
Supports old Mac OS X versions that may use a couple of Carbon calls:
GetKeys used by OS X 10.3 or before (in Fl::get_key())