[gnome-characters/wip/dueno/local-scripts] libgc: Fix setlocale calls in gc_*_for_locale



commit 395159ea55feb6d59f4ec67497dc3064d7f09764
Author: Daiki Ueno <dueno src gnome org>
Date:   Tue Jun 16 18:41:47 2015 +0900

    libgc: Fix setlocale calls in gc_*_for_locale

 lib/gc.c |   55 ++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/lib/gc.c b/lib/gc.c
index 8ea432a..79695c9 100644
--- a/lib/gc.c
+++ b/lib/gc.c
@@ -949,25 +949,29 @@ GList *
 gc_get_scripts_for_locale (const gchar *locale)
 {
   gchar *old_locale;
-  GSettings *settings;
-  GVariant *value;
   GList *result = NULL;
 
-  old_locale = g_strdup (setlocale (LC_MESSAGES, locale));
+  old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
   if (!old_locale)
     return NULL;
 
-  settings = g_settings_new ("org.gnome.Characters");
-  value = g_settings_get_default_value (settings, "local-scripts");
-  if (value)
+  if (setlocale (LC_MESSAGES, locale))
     {
-      GVariantIter iter;
-      gchar *script;
+      GSettings *settings;
+      GVariant *value;
 
-      g_variant_iter_init (&iter, value);
-      while (g_variant_iter_next (&iter, "s", &script))
-       result = g_list_append (result, script);
-      g_variant_unref (value);
+      settings = g_settings_new ("org.gnome.Characters");
+      value = g_settings_get_default_value (settings, "local-scripts");
+      if (value)
+       {
+         GVariantIter iter;
+         gchar *script;
+
+         g_variant_iter_init (&iter, value);
+         while (g_variant_iter_next (&iter, "s", &script))
+           result = g_list_append (result, script);
+         g_variant_unref (value);
+       }
     }
 
   setlocale (LC_MESSAGES, old_locale);
@@ -986,24 +990,29 @@ gchar *
 gc_get_character_for_locale (const gchar *locale)
 {
   gchar *old_locale;
-  GSettings *settings;
-  GVariant *value;
   gchar *result = NULL;
 
-  old_locale = g_strdup (setlocale (LC_MESSAGES, locale));
+  old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
   if (!old_locale)
     return g_strdup ("?");
 
-  settings = g_settings_new ("org.gnome.Characters");
-  value = g_settings_get_default_value (settings, "local-scripts-character");
-  setlocale (LC_MESSAGES, old_locale);
-  g_free (old_locale);
-
-  if (value)
+  if (setlocale (LC_MESSAGES, locale))
     {
-      result = g_variant_dup_string (value, NULL);
-      g_variant_unref (value);
+      GSettings *settings;
+      GVariant *value;
+
+      settings = g_settings_new ("org.gnome.Characters");
+      value = g_settings_get_default_value (settings,
+                                           "local-scripts-character");
+      if (value)
+       {
+         result = g_variant_dup_string (value, NULL);
+         g_variant_unref (value);
+       }
     }
 
+  setlocale (LC_MESSAGES, old_locale);
+  g_free (old_locale);
+
   return result;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]