This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct illegal use of >> in Exporter POD.
[perl5.git] / locale.c
index 3fc55a8..8d49fac 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -514,8 +514,14 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
                     (printwarn &&
                      (!(p = PerlEnv_getenv("PERL_BADLANG")) || atoi(p))));
     bool done = FALSE;
+#ifdef WIN32
+    /* In some systems you can find out the system default locale
+     * and use that as the fallback locale. */
+#   define SYSTEM_DEFAULT_LOCALE
+#endif
+#ifdef SYSTEM_DEFAULT_LOCALE
     const char *system_default_locale = NULL;
-
+#endif
 
 #ifndef LOCALE_ENVIRON_REQUIRED
     PERL_UNUSED_VAR(done);
@@ -600,8 +606,8 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
              * sense */
             setlocale_failure = FALSE;
 
-#ifdef WIN32
-
+#ifdef SYSTEM_DEFAULT_LOCALE
+#  ifdef WIN32
             /* On Windows machines, an entry of "" after the 0th means to use
              * the system default locale, which we now proceed to get. */
             if (strEQ(trial_locale, "")) {
@@ -624,7 +630,8 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
 
                 trial_locale = system_default_locale;
             }
-#endif
+#  endif /* WIN32 */
+#endif /* SYSTEM_DEFAULT_LOCALE */
         }
 
 #ifdef LC_ALL
@@ -846,12 +853,14 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
                 description = "the standard locale";
                 name = "C";
             }
+#ifdef SYSTEM_DEFAULT_LOCALE
             else if (strEQ(trial_locales[i], "")) {
                 description = "the system default locale";
                 if (system_default_locale) {
                     name = system_default_locale;
                 }
             }
+#endif /* SYSTEM_DEFAULT_LOCALE */
             else {
                 description = "a fallback locale";
                 name = trial_locales[i];
@@ -1077,6 +1086,7 @@ S_is_cur_LC_category_utf8(pTHX_ int category)
                 Safefree(save_input_locale);
                 return is_utf8;
             }
+            Safefree(codeset);
         }
 
 #   endif
@@ -1109,7 +1119,7 @@ S_is_cur_LC_category_utf8(pTHX_ int category)
             (void) mbtowc(&wc, NULL, 0);    /* Reset any shift state */
             GCC_DIAG_RESTORE;
             errno = 0;
-            if (mbtowc(&wc, HYPHEN_UTF8, strlen(HYPHEN_UTF8))
+            if ((size_t)mbtowc(&wc, HYPHEN_UTF8, strlen(HYPHEN_UTF8))
                                                         != strlen(HYPHEN_UTF8)
                 || wc != (wchar_t) 0x2010)
             {
@@ -1181,20 +1191,20 @@ S_is_cur_LC_category_utf8(pTHX_ int category)
         && *(save_input_locale + final_pos - 3) == '5'
         && *(save_input_locale + final_pos - 4) == '6')
     {
-        Safefree(save_input_locale);
         DEBUG_L(PerlIO_printf(Perl_debug_log,
                         "Locale %s ends with 10056 in name, is UTF-8 locale\n",
                         save_input_locale));
+        Safefree(save_input_locale);
         return TRUE;
     }
 #endif
 
     /* Other common encodings are the ISO 8859 series, which aren't UTF-8 */
     if (instr(save_input_locale, "8859")) {
-        Safefree(save_input_locale);
         DEBUG_L(PerlIO_printf(Perl_debug_log,
                              "Locale %s has 8859 in name, not UTF-8 locale\n",
                              save_input_locale));
+        Safefree(save_input_locale);
         return FALSE;
     }