summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-11-18 21:45:46 -0700
committerKarl Williamson <khw@cpan.org>2014-11-19 09:38:47 -0700
commiteb9d0228c41a1528b2864e335094c0c25258789a (patch)
treea658846600e100dca7ddad44bc8cc719354146ec /locale.c
parent96d11ca8c0301ed6fd2f23dec68c455ef2787aa7 (diff)
downloadperl-eb9d0228c41a1528b2864e335094c0c25258789a.tar.gz
locale.c: Account for setlocale using static storage
Some systems setlocale()s use static storage for the locale name returned by it, so that a subsequent setlocale overwrites it. Therefore, you must make a copy of the name if you want it to work after the next setlocale. Thanks to Craig Berry for finding and diagnosing this problem.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/locale.c b/locale.c
index 995c926fe2..c8460462a1 100644
--- a/locale.c
+++ b/locale.c
@@ -351,10 +351,17 @@ Perl_new_ctype(pTHX_ const char *newctype)
#endif
if (bad_count || multi_byte_locale) {
+
+ /* We have to save 'newctype' because the setlocale() just below
+ * may destroy it. The next setlocale() further down should
+ * restore it properly so that the intermediate change here is
+ * transparent to this function's caller */
+ const char * const badlocale = savepv(newctype);
+
setlocale(LC_CTYPE, "C");
Perl_warner(aTHX_ packWARN(WARN_LOCALE),
"Locale '%s' may not work well.%s%s%s\n",
- newctype,
+ badlocale,
(multi_byte_locale)
? " Some characters in it are not recognized by"
" Perl."
@@ -368,7 +375,7 @@ Perl_new_ctype(pTHX_ const char *newctype)
? bad_chars_list
: ""
);
- setlocale(LC_CTYPE, newctype);
+ setlocale(LC_CTYPE, badlocale);
}
}