summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-01-22 18:44:49 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2020-01-22 18:44:49 +0100
commita47df744310de9fb8cc5d12c9685a3d4fa564110 (patch)
tree6eb66e2b229c810b8be5fc9353ed6a259054a2ee /src/drivers
parentbcc2f4c575df31561642cf192d33ee69ddfbd5e1 (diff)
Fix preservation of the caller's locale when running GTK dialogs.
There are now 2 kinds of GTK libraries (V2 and V3) and two dialogs the file chooser and the printer chooser.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/X11/Fl_X11_System_Driver.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx
index 3c4cc043d..79193a04d 100644
--- a/src/drivers/X11/Fl_X11_System_Driver.cxx
+++ b/src/drivers/X11/Fl_X11_System_Driver.cxx
@@ -569,8 +569,21 @@ bool Fl_X11_System_Driver::probe_for_GTK(int major, int minor, void **ptr_gtk) {
init_f = (init_t)dlsym(*ptr_gtk, "gtk_init_check");
if (!init_f) return false;
}
+
+ // The point here is that after running gtk_init_check, the calling program's current locale can be modified.
+ // To avoid that, we memorize the calling program's current locale and restore the locale
+ // before returning.
+ char *before = NULL;
+ // record in "before" the calling program's current locale
+ char *p = setlocale(LC_ALL, NULL);
+ if (p) before = strdup(p);
int ac = 0;
- init_f(&ac, NULL);
+ init_f(&ac, NULL); // may change the locale
+ if (before) {
+ setlocale(LC_ALL, before); // restore calling program's current locale
+ free(before);
+ }
+
// now check if running version is high enough
if (dlsym(*ptr_gtk, "gtk_get_major_version") == NULL) { // YES indicates V 3
typedef const char* (*check_t)(int, int, int);