[epiphany] Resync gnome-languages with gnome-desktop



commit 888040030cf8c4d00a7fb58dd9da2085bc449646
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Mon Feb 25 14:15:20 2019 -0600

    Resync gnome-languages with gnome-desktop
    
    For setlocale -> uselocale safety fix.

 lib/contrib/gnome-languages.c | 49 ++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/lib/contrib/gnome-languages.c b/lib/contrib/gnome-languages.c
index f5c31ce4a..b754229e6 100644
--- a/lib/contrib/gnome-languages.c
+++ b/lib/contrib/gnome-languages.c
@@ -288,15 +288,15 @@ gnome_normalize_locale (const char *locale)
 static gboolean
 language_name_is_valid (const char *language_name)
 {
-        gboolean  is_valid;
-        int lc_type_id = LC_MESSAGES;
-        g_autofree char *old_locale = NULL;
+        locale_t locale;
 
-        old_locale = g_strdup (setlocale (lc_type_id, NULL));
-        is_valid = setlocale (lc_type_id, language_name) != NULL;
-        setlocale (lc_type_id, old_locale);
+        locale = newlocale (LC_MESSAGES_MASK, language_name, (locale_t) 0);
+        if (locale != (locale_t) 0) {
+                freelocale (locale);
+                return TRUE;
+        }
 
-        return is_valid;
+        return FALSE;
 }
 
 static void
@@ -304,14 +304,16 @@ language_name_get_codeset_details (const char  *language_name,
                                    char       **pcodeset,
                                    gboolean    *is_utf8)
 {
-        g_autofree char *old_locale = NULL;
+        locale_t locale;
+        locale_t old_locale;
         const char *codeset = NULL;
 
-        old_locale = g_strdup (setlocale (LC_CTYPE, NULL));
-
-        if (setlocale (LC_CTYPE, language_name) == NULL)
+        locale = newlocale (LC_CTYPE_MASK, language_name, (locale_t) 0);
+        if (locale == (locale_t) 0)
                 return;
 
+        old_locale = uselocale (locale);
+
         codeset = nl_langinfo (CODESET);
 
         if (pcodeset != NULL) {
@@ -324,7 +326,8 @@ language_name_get_codeset_details (const char  *language_name,
                 *is_utf8 = strcmp (normalized_codeset, "UTF-8") == 0;
         }
 
-        setlocale (LC_CTYPE, old_locale);
+        uselocale (old_locale);
+        freelocale (locale);
 }
 
 /**
@@ -701,12 +704,13 @@ get_translated_language (const char *code,
 
         name = NULL;
         if (language != NULL) {
-                const char  *translated_name;
-                g_autofree char *old_locale = NULL;
+                const char *translated_name;
+                locale_t loc;
+                locale_t old_locale;
 
                 if (locale != NULL) {
-                        old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
-                        setlocale (LC_MESSAGES, locale);
+                        loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
+                        old_locale = uselocale (loc);
                 }
 
                 if (is_fallback_language (code)) {
@@ -719,7 +723,8 @@ get_translated_language (const char *code,
                 }
 
                 if (locale != NULL) {
-                        setlocale (LC_MESSAGES, old_locale);
+                        uselocale (old_locale);
+                        freelocale (loc);
                 }
         }
 
@@ -756,12 +761,13 @@ get_translated_territory (const char *code,
         name = NULL;
         if (territory != NULL) {
                 const char *translated_territory;
-                g_autofree char *old_locale = NULL;
+                locale_t loc;
+                locale_t old_locale;
                 g_autofree char *tmp = NULL;
 
                 if (locale != NULL) {
-                        old_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
-                        setlocale (LC_MESSAGES, locale);
+                        loc = newlocale (LC_MESSAGES_MASK, locale, (locale_t) 0);
+                        old_locale = uselocale (loc);
                 }
 
                 translated_territory = dgettext ("iso_3166", territory);
@@ -769,7 +775,8 @@ get_translated_territory (const char *code,
                 name = capitalize_utf8_string (tmp);
 
                 if (locale != NULL) {
-                        setlocale (LC_MESSAGES, old_locale);
+                        uselocale (old_locale);
+                        freelocale (loc);
                 }
         }
 


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