3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 * 2002, 2003, 2005, 2006, 2007, 2008 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * A Elbereth Gilthoniel,
13 * silivren penna míriel
14 * o menel aglar elenath!
15 * Na-chaered palan-díriel
16 * o galadhremmin ennorath,
17 * Fanuilos, le linnathon
18 * nef aear, si nef aearon!
20 * [p.238 of _The Lord of the Rings_, II/i: "Many Meetings"]
23 /* utility functions for handling locale-specific stuff like what
24 * character represents the decimal point.
28 #define PERL_IN_LOCALE_C
32 # include <langinfo.h>
40 * Standardize the locale name from a string returned by 'setlocale'.
42 * The typical return value of setlocale() is either
43 * (1) "xx_YY" if the first argument of setlocale() is not LC_ALL
44 * (2) "xa_YY xb_YY ..." if the first argument of setlocale() is LC_ALL
45 * (the space-separated values represent the various sublocales,
46 * in some unspecified order). This is not handled by this function.
48 * In some platforms it has a form like "LC_SOMETHING=Lang_Country.866\n",
49 * which is harmful for further use of the string in setlocale(). This
50 * function removes the trailing new line and everything up through the '='
54 S_stdize_locale(pTHX_ char *locs)
56 const char * const s = strchr(locs, '=');
59 PERL_ARGS_ASSERT_STDIZE_LOCALE;
62 const char * const t = strchr(s, '.');
65 const char * const u = strchr(t, '\n');
66 if (u && (u[1] == 0)) {
67 const STRLEN len = u - s;
68 Move(s + 1, locs, len, char);
76 Perl_croak(aTHX_ "Can't fix broken locale name \"%s\"", locs);
84 Perl_set_numeric_radix(pTHX)
86 #ifdef USE_LOCALE_NUMERIC
88 # ifdef HAS_LOCALECONV
89 const struct lconv* const lc = localeconv();
91 if (lc && lc->decimal_point) {
92 if (lc->decimal_point[0] == '.' && lc->decimal_point[1] == 0) {
93 SvREFCNT_dec(PL_numeric_radix_sv);
94 PL_numeric_radix_sv = NULL;
97 if (PL_numeric_radix_sv)
98 sv_setpv(PL_numeric_radix_sv, lc->decimal_point);
100 PL_numeric_radix_sv = newSVpv(lc->decimal_point, 0);
101 if (! is_ascii_string((U8 *) lc->decimal_point, 0)
102 && is_utf8_string((U8 *) lc->decimal_point, 0)
103 && is_cur_LC_category_utf8(LC_NUMERIC))
105 SvUTF8_on(PL_numeric_radix_sv);
110 PL_numeric_radix_sv = NULL;
111 # endif /* HAS_LOCALECONV */
112 #endif /* USE_LOCALE_NUMERIC */
116 * Set up for a new numeric locale.
119 Perl_new_numeric(pTHX_ const char *newnum)
121 #ifdef USE_LOCALE_NUMERIC
126 Safefree(PL_numeric_name);
127 PL_numeric_name = NULL;
128 PL_numeric_standard = TRUE;
129 PL_numeric_local = TRUE;
133 save_newnum = stdize_locale(savepv(newnum));
134 if (! PL_numeric_name || strNE(PL_numeric_name, save_newnum)) {
135 Safefree(PL_numeric_name);
136 PL_numeric_name = save_newnum;
139 PL_numeric_standard = ((*save_newnum == 'C' && save_newnum[1] == '\0')
140 || strEQ(save_newnum, "POSIX"));
141 PL_numeric_local = TRUE;
144 #endif /* USE_LOCALE_NUMERIC */
148 Perl_set_numeric_standard(pTHX)
150 #ifdef USE_LOCALE_NUMERIC
153 if (! PL_numeric_standard) {
154 setlocale(LC_NUMERIC, "C");
155 PL_numeric_standard = TRUE;
156 PL_numeric_local = FALSE;
160 #endif /* USE_LOCALE_NUMERIC */
164 Perl_set_numeric_local(pTHX)
166 #ifdef USE_LOCALE_NUMERIC
169 if (! PL_numeric_local) {
170 setlocale(LC_NUMERIC, PL_numeric_name);
171 PL_numeric_standard = FALSE;
172 PL_numeric_local = TRUE;
176 #endif /* USE_LOCALE_NUMERIC */
180 * Set up for a new ctype locale.
183 Perl_new_ctype(pTHX_ const char *newctype)
185 #ifdef USE_LOCALE_CTYPE
189 PERL_ARGS_ASSERT_NEW_CTYPE;
191 for (i = 0; i < 256; i++) {
192 if (isUPPER_LC((U8) i))
193 PL_fold_locale[i] = toLOWER_LC((U8) i);
194 else if (isLOWER_LC((U8) i))
195 PL_fold_locale[i] = toUPPER_LC((U8) i);
197 PL_fold_locale[i] = i;
200 #endif /* USE_LOCALE_CTYPE */
201 PERL_ARGS_ASSERT_NEW_CTYPE;
202 PERL_UNUSED_ARG(newctype);
207 * Set up for a new collation locale.
210 Perl_new_collate(pTHX_ const char *newcoll)
212 #ifdef USE_LOCALE_COLLATE
216 if (PL_collation_name) {
218 Safefree(PL_collation_name);
219 PL_collation_name = NULL;
221 PL_collation_standard = TRUE;
222 PL_collxfrm_base = 0;
223 PL_collxfrm_mult = 2;
227 if (! PL_collation_name || strNE(PL_collation_name, newcoll)) {
229 Safefree(PL_collation_name);
230 PL_collation_name = stdize_locale(savepv(newcoll));
231 PL_collation_standard = ((*newcoll == 'C' && newcoll[1] == '\0')
232 || strEQ(newcoll, "POSIX"));
235 /* 2: at most so many chars ('a', 'b'). */
236 /* 50: surely no system expands a char more. */
237 #define XFRMBUFSIZE (2 * 50)
238 char xbuf[XFRMBUFSIZE];
239 const Size_t fa = strxfrm(xbuf, "a", XFRMBUFSIZE);
240 const Size_t fb = strxfrm(xbuf, "ab", XFRMBUFSIZE);
241 const SSize_t mult = fb - fa;
242 if (mult < 1 && !(fa == 0 && fb == 0))
243 Perl_croak(aTHX_ "panic: strxfrm() gets absurd - a => %"UVuf", ab => %"UVuf,
245 PL_collxfrm_base = (fa > (Size_t)mult) ? (fa - mult) : 0;
246 PL_collxfrm_mult = mult;
250 #endif /* USE_LOCALE_COLLATE */
254 * Initialize locale awareness.
257 Perl_init_i18nl10n(pTHX_ int printwarn)
261 * 1 = set ok or not applicable,
262 * 0 = fallback to C locale,
263 * -1 = fallback to C locale failed
266 #if defined(USE_LOCALE)
269 #ifdef USE_LOCALE_CTYPE
270 char *curctype = NULL;
271 #endif /* USE_LOCALE_CTYPE */
272 #ifdef USE_LOCALE_COLLATE
273 char *curcoll = NULL;
274 #endif /* USE_LOCALE_COLLATE */
275 #ifdef USE_LOCALE_NUMERIC
277 #endif /* USE_LOCALE_NUMERIC */
279 char * const language = PerlEnv_getenv("LANGUAGE");
281 /* NULL uses the existing already set up locale */
282 const char * const setlocale_init = (PerlEnv_getenv("PERL_SKIP_LOCALE_INIT"))
285 char * const lc_all = PerlEnv_getenv("LC_ALL");
286 char * const lang = PerlEnv_getenv("LANG");
287 bool setlocale_failure = FALSE;
289 #ifdef LOCALE_ENVIRON_REQUIRED
292 * Ultrix setlocale(..., "") fails if there are no environment
293 * variables from which to get a locale name.
300 if (setlocale(LC_ALL, setlocale_init))
303 setlocale_failure = TRUE;
305 if (!setlocale_failure) {
306 # ifdef USE_LOCALE_CTYPE
310 (!done && (lang || PerlEnv_getenv("LC_CTYPE")))
311 ? setlocale_init : NULL)))
312 setlocale_failure = TRUE;
314 curctype = savepv(curctype);
315 # endif /* USE_LOCALE_CTYPE */
316 # ifdef USE_LOCALE_COLLATE
319 setlocale(LC_COLLATE,
320 (!done && (lang || PerlEnv_getenv("LC_COLLATE")))
321 ? setlocale_init : NULL)))
322 setlocale_failure = TRUE;
324 curcoll = savepv(curcoll);
325 # endif /* USE_LOCALE_COLLATE */
326 # ifdef USE_LOCALE_NUMERIC
329 setlocale(LC_NUMERIC,
330 (!done && (lang || PerlEnv_getenv("LC_NUMERIC")))
331 ? setlocale_init : NULL)))
332 setlocale_failure = TRUE;
334 curnum = savepv(curnum);
335 # endif /* USE_LOCALE_NUMERIC */
340 #endif /* !LOCALE_ENVIRON_REQUIRED */
343 if (! setlocale(LC_ALL, setlocale_init))
344 setlocale_failure = TRUE;
347 if (!setlocale_failure) {
348 #ifdef USE_LOCALE_CTYPE
350 if (! (curctype = setlocale(LC_CTYPE, setlocale_init)))
351 setlocale_failure = TRUE;
353 curctype = savepv(curctype);
354 #endif /* USE_LOCALE_CTYPE */
355 #ifdef USE_LOCALE_COLLATE
357 if (! (curcoll = setlocale(LC_COLLATE, setlocale_init)))
358 setlocale_failure = TRUE;
360 curcoll = savepv(curcoll);
361 #endif /* USE_LOCALE_COLLATE */
362 #ifdef USE_LOCALE_NUMERIC
364 if (! (curnum = setlocale(LC_NUMERIC, setlocale_init)))
365 setlocale_failure = TRUE;
367 curnum = savepv(curnum);
368 #endif /* USE_LOCALE_NUMERIC */
371 if (setlocale_failure) {
373 const bool locwarn = (printwarn > 1 ||
375 (!(p = PerlEnv_getenv("PERL_BADLANG")) || atoi(p))));
380 PerlIO_printf(Perl_error_log,
381 "perl: warning: Setting locale failed.\n");
385 PerlIO_printf(Perl_error_log,
386 "perl: warning: Setting locale failed for the categories:\n\t");
387 #ifdef USE_LOCALE_CTYPE
389 PerlIO_printf(Perl_error_log, "LC_CTYPE ");
390 #endif /* USE_LOCALE_CTYPE */
391 #ifdef USE_LOCALE_COLLATE
393 PerlIO_printf(Perl_error_log, "LC_COLLATE ");
394 #endif /* USE_LOCALE_COLLATE */
395 #ifdef USE_LOCALE_NUMERIC
397 PerlIO_printf(Perl_error_log, "LC_NUMERIC ");
398 #endif /* USE_LOCALE_NUMERIC */
399 PerlIO_printf(Perl_error_log, "\n");
403 PerlIO_printf(Perl_error_log,
404 "perl: warning: Please check that your locale settings:\n");
407 PerlIO_printf(Perl_error_log,
408 "\tLANGUAGE = %c%s%c,\n",
409 language ? '"' : '(',
410 language ? language : "unset",
411 language ? '"' : ')');
414 PerlIO_printf(Perl_error_log,
415 "\tLC_ALL = %c%s%c,\n",
417 lc_all ? lc_all : "unset",
420 #if defined(USE_ENVIRON_ARRAY)
423 for (e = environ; *e; e++) {
424 if (strnEQ(*e, "LC_", 3)
425 && strnNE(*e, "LC_ALL=", 7)
426 && (p = strchr(*e, '=')))
427 PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n",
428 (int)(p - *e), *e, p + 1);
432 PerlIO_printf(Perl_error_log,
433 "\t(possibly more locale environment variables)\n");
436 PerlIO_printf(Perl_error_log,
439 lang ? lang : "unset",
442 PerlIO_printf(Perl_error_log,
443 " are supported and installed on your system.\n");
448 if (setlocale(LC_ALL, "C")) {
450 PerlIO_printf(Perl_error_log,
451 "perl: warning: Falling back to the standard locale (\"C\").\n");
456 PerlIO_printf(Perl_error_log,
457 "perl: warning: Failed to fall back to the standard locale (\"C\").\n");
464 #ifdef USE_LOCALE_CTYPE
465 || !(curctype || setlocale(LC_CTYPE, "C"))
466 #endif /* USE_LOCALE_CTYPE */
467 #ifdef USE_LOCALE_COLLATE
468 || !(curcoll || setlocale(LC_COLLATE, "C"))
469 #endif /* USE_LOCALE_COLLATE */
470 #ifdef USE_LOCALE_NUMERIC
471 || !(curnum || setlocale(LC_NUMERIC, "C"))
472 #endif /* USE_LOCALE_NUMERIC */
476 PerlIO_printf(Perl_error_log,
477 "perl: warning: Cannot fall back to the standard locale (\"C\").\n");
481 #endif /* ! LC_ALL */
483 #ifdef USE_LOCALE_CTYPE
485 curctype = savepv(setlocale(LC_CTYPE, NULL));
486 #endif /* USE_LOCALE_CTYPE */
487 #ifdef USE_LOCALE_COLLATE
489 curcoll = savepv(setlocale(LC_COLLATE, NULL));
490 #endif /* USE_LOCALE_COLLATE */
491 #ifdef USE_LOCALE_NUMERIC
493 curnum = savepv(setlocale(LC_NUMERIC, NULL));
494 #endif /* USE_LOCALE_NUMERIC */
498 #ifdef USE_LOCALE_CTYPE
500 #endif /* USE_LOCALE_CTYPE */
502 #ifdef USE_LOCALE_COLLATE
503 new_collate(curcoll);
504 #endif /* USE_LOCALE_COLLATE */
506 #ifdef USE_LOCALE_NUMERIC
508 #endif /* USE_LOCALE_NUMERIC */
512 #if defined(USE_PERLIO) && defined(USE_LOCALE_CTYPE)
514 /* Set PL_utf8locale to TRUE if using PerlIO _and_
515 the current LC_CTYPE locale is UTF-8.
516 If PL_utf8locale and PL_unicode (set by -C or by $ENV{PERL_UNICODE})
517 are true, perl.c:S_parse_body() will turn on the PerlIO :utf8 layer
518 on STDIN, STDOUT, STDERR, _and_ the default open discipline.
520 PL_utf8locale = is_cur_LC_category_utf8(LC_CTYPE);
522 /* Set PL_unicode to $ENV{PERL_UNICODE} if using PerlIO.
523 This is an alternative to using the -C command line switch
524 (the -C if present will override this). */
526 const char *p = PerlEnv_getenv("PERL_UNICODE");
527 PL_unicode = p ? parse_unicode_opts(&p) : 0;
528 if (PL_unicode & PERL_UNICODE_UTF8CACHEASSERT_FLAG)
533 #ifdef USE_LOCALE_CTYPE
535 #endif /* USE_LOCALE_CTYPE */
536 #ifdef USE_LOCALE_COLLATE
538 #endif /* USE_LOCALE_COLLATE */
539 #ifdef USE_LOCALE_NUMERIC
541 #endif /* USE_LOCALE_NUMERIC */
543 #endif /* USE_LOCALE */
548 #ifdef USE_LOCALE_COLLATE
551 * mem_collxfrm() is a bit like strxfrm() but with two important
552 * differences. First, it handles embedded NULs. Second, it allocates
553 * a bit more memory than needed for the transformed data itself.
554 * The real transformed data begins at offset sizeof(collationix).
555 * Please see sv_collxfrm() to see how this is used.
559 Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen)
563 STRLEN xAlloc, xin, xout; /* xalloc is a reserved word in VC */
565 PERL_ARGS_ASSERT_MEM_COLLXFRM;
567 /* the first sizeof(collationix) bytes are used by sv_collxfrm(). */
568 /* the +1 is for the terminating NUL. */
570 xAlloc = sizeof(PL_collation_ix) + PL_collxfrm_base + (PL_collxfrm_mult * len) + 1;
571 Newx(xbuf, xAlloc, char);
575 *(U32*)xbuf = PL_collation_ix;
576 xout = sizeof(PL_collation_ix);
577 for (xin = 0; xin < len; ) {
581 xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
582 if (xused >= PERL_INT_MAX)
584 if ((STRLEN)xused < xAlloc - xout)
586 xAlloc = (2 * xAlloc) + 1;
587 Renew(xbuf, xAlloc, char);
592 xin += strlen(s + xin) + 1;
595 /* Embedded NULs are understood but silently skipped
596 * because they make no sense in locale collation. */
600 *xlen = xout - sizeof(PL_collation_ix);
609 #endif /* USE_LOCALE_COLLATE */
614 S_is_cur_LC_category_utf8(pTHX_ int category)
616 /* Returns TRUE if the current locale for 'category' is UTF-8; FALSE
617 * otherwise. 'category' may not be LC_ALL. If the platform doesn't have
618 * nl_langinfo(), this employs a heuristic, which hence could give the
619 * wrong result. It errs on the side of not being a UTF-8 locale. */
621 char *save_input_locale = NULL;
625 assert(category != LC_ALL);
628 /* First dispose of the trivial cases */
629 save_input_locale = stdize_locale(setlocale(category, NULL));
630 if (! save_input_locale) {
631 return FALSE; /* XXX maybe should croak */
633 if ((*save_input_locale == 'C' && save_input_locale[1] == '\0')
634 || strEQ(save_input_locale, "POSIX"))
639 save_input_locale = savepv(save_input_locale);
641 #if defined(HAS_NL_LANGINFO) && defined(CODESET) && defined(USE_LOCALE_CTYPE)
643 { /* Next try nl_langinfo if available */
645 char *save_ctype_locale = NULL;
646 char *codeset = NULL;
648 if (category != LC_CTYPE) { /* nl_langinfo works only on LC_CTYPE */
650 /* Get the current LC_CTYPE locale */
651 save_ctype_locale = stdize_locale(savepv(setlocale(LC_CTYPE, NULL)));
652 if (! save_ctype_locale) {
653 goto cant_use_nllanginfo;
656 /* If LC_CTYPE and the desired category use the same locale, this
657 * means that finding the value for LC_CTYPE is the same as finding
658 * the value for the desired category. Otherwise, switch LC_CTYPE
659 * to the desired category's locale */
660 if (strEQ(save_ctype_locale, save_input_locale)) {
661 Safefree(save_ctype_locale);
662 save_ctype_locale = NULL;
664 else if (! setlocale(LC_CTYPE, save_input_locale)) {
665 Safefree(save_ctype_locale);
666 goto cant_use_nllanginfo;
670 /* Here the current LC_CTYPE is set to the locale of the category whose
671 * information is desired. This means that nl_langinfo() should give
672 * the correct results */
673 codeset = savepv(nl_langinfo(CODESET));
677 /* If we switched LC_CTYPE, switch back */
678 if (save_ctype_locale) {
679 setlocale(LC_CTYPE, save_ctype_locale);
680 Safefree(save_ctype_locale);
683 is_utf8 = foldEQ(codeset, STR_WITH_LEN("UTF-8"))
684 || foldEQ(codeset, STR_WITH_LEN("UTF8"));
687 Safefree(save_input_locale);
694 #endif /* HAS_NL_LANGINFO etc */
696 /* nl_langinfo not available or failed somehow. Look at the locale name to
697 * see if it matches qr/UTF -? 8 /ix */
699 final_pos = strlen(save_input_locale) - 1;
700 if (final_pos >= 3) {
701 char *name = save_input_locale;
703 /* Find next 'U' or 'u' and look from there */
704 while ((name += strcspn(name, "Uu") + 1)
705 <= save_input_locale + final_pos - 2)
707 if (toFOLD(*(name)) != 't'
708 || toFOLD(*(name + 1)) != 'f')
713 if (*(name) == '-') {
714 if ((name > save_input_locale + final_pos - 1)) {
719 if (*(name) == '8') {
720 Safefree(save_input_locale);
727 /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx */
729 && *(save_input_locale + final_pos - 0) == '1'
730 && *(save_input_locale + final_pos - 1) == '0'
731 && *(save_input_locale + final_pos - 2) == '0'
732 && *(save_input_locale + final_pos - 3) == '5'
733 && *(save_input_locale + final_pos - 4) == '6')
735 Safefree(save_input_locale);
740 /* Other common encodings are the ISO 8859 series, which aren't UTF-8 */
741 if (instr(save_input_locale, "8859")) {
742 Safefree(save_input_locale);
746 #ifdef HAS_LOCALECONV
748 # ifdef USE_LOCALE_MONETARY
750 /* Here, there is nothing in the locale name to indicate whether the locale
751 * is UTF-8 or not. This "name", the return of setlocale(), is actually
752 * defined to be opaque, so we can't really rely on the absence of various
753 * substrings in the name to indicate its UTF-8ness. Look at the locale's
754 * currency symbol. Often that will be in the native script, and if the
755 * symbol isn't in UTF-8, we know that the locale isn't. If it is
756 * non-ASCII UTF-8, we infer that the locale is too.
757 * To do this, like above for LC_CTYPE, we first set LC_MONETARY to the
758 * locale of the desired category, if it isn't that locale already */
761 char *save_monetary_locale = NULL;
762 bool illegal_utf8 = FALSE;
763 bool only_ascii = FALSE;
764 const struct lconv* const lc = localeconv();
766 if (category != LC_MONETARY) {
768 save_monetary_locale = stdize_locale(savepv(setlocale(LC_MONETARY,
770 if (! save_monetary_locale) {
771 goto cant_use_monetary;
774 if (strNE(save_monetary_locale, save_input_locale)) {
775 if (! setlocale(LC_MONETARY, save_input_locale)) {
776 Safefree(save_monetary_locale);
777 goto cant_use_monetary;
782 /* Here the current LC_MONETARY is set to the locale of the category
783 * whose information is desired. */
785 if (lc && lc->currency_symbol) {
786 if (! is_utf8_string((U8 *) lc->currency_symbol, 0)) {
789 else if (is_ascii_string((U8 *) lc->currency_symbol, 0)) {
794 /* If we changed it, restore LC_MONETARY to its original locale */
795 if (save_monetary_locale) {
796 setlocale(LC_MONETARY, save_monetary_locale);
797 Safefree(save_monetary_locale);
800 Safefree(save_input_locale);
802 /* It isn't a UTF-8 locale if the symbol is not legal UTF-8; otherwise
803 * assume the locale is UTF-8 if and only if the symbol is non-ascii
804 * UTF-8. (We can't really tell if the locale is UTF-8 or not if the
805 * symbol is just a '$', so we err on the side of it not being UTF-8)
807 return (illegal_utf8)
814 # endif /* USE_LOCALE_MONETARY */
815 #endif /* HAS_LOCALECONV */
817 #if 0 && defined(HAS_STRERROR) && defined(USE_LOCALE_MESSAGES)
819 /* This code is ifdefd out because it was found to not be necessary in testing
820 * on our dromedary test machine, which has over 700 locales. There, looking
821 * at just the currency symbol gave essentially the same results as doing this
822 * extra work. Executing this also caused segfaults in miniperl. I left it in
823 * so as to avoid rewriting it if real-world experience indicates that
824 * dromedary is an outlier. Essentially, instead of returning abpve if we
825 * haven't found illegal utf8, we continue on and examine all the strerror()
826 * messages on the platform for utf8ness. If all are ASCII, we still don't
827 * know the answer; but otherwise we have a pretty good indication of the
828 * utf8ness. The reason this doesn't necessarily help much is that the
829 * messages may not have been translated into the locale. The currency symbol
830 * is much more likely to have been translated. The code below would need to
831 * be altered somewhat to just be a continuation of testing the currency
834 unsigned int failures = 0, non_ascii = 0;
835 char *save_messages_locale = NULL;
837 /* Like above for LC_CTYPE, we set LC_MESSAGES to the locale of the
838 * desired category, if it isn't that locale already */
840 if (category != LC_MESSAGES) {
842 save_messages_locale = stdize_locale(savepv(setlocale(LC_MESSAGES,
844 if (! save_messages_locale) {
845 goto cant_use_messages;
848 if (strEQ(save_messages_locale, save_input_locale)) {
849 Safefree(save_input_locale);
851 else if (! setlocale(LC_MESSAGES, save_input_locale)) {
852 Safefree(save_messages_locale);
853 goto cant_use_messages;
857 /* Here the current LC_MESSAGES is set to the locale of the category
858 * whose information is desired. Look through all the messages */
861 #ifdef HAS_SYS_ERRLIST
866 const U8* const errmsg = (U8 *) Strerror(e) ;
869 if (! is_utf8_string(errmsg, 0)) {
873 else if (! is_ascii_string(errmsg, 0)) {
878 /* And, if we changed it, restore LC_MESSAGES to its original locale */
879 if (save_messages_locale) {
880 setlocale(LC_MESSAGES, save_messages_locale);
881 Safefree(save_messages_locale);
884 /* Any non-UTF-8 message means not a UTF-8 locale; if all are valid,
885 * any non-ascii means it is one; otherwise we assume it isn't */
886 return (failures) ? FALSE : non_ascii;
893 Safefree(save_input_locale);
901 * c-indentation-style: bsd
903 * indent-tabs-mode: nil
906 * ex: set ts=8 sts=4 sw=4 et: