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;
137 PL_numeric_standard = ((*save_newnum == 'C' && save_newnum[1] == '\0')
138 || strEQ(save_newnum, "POSIX"));
139 PL_numeric_local = TRUE;
143 Safefree(save_newnum);
146 #endif /* USE_LOCALE_NUMERIC */
150 Perl_set_numeric_standard(pTHX)
152 #ifdef USE_LOCALE_NUMERIC
155 if (! PL_numeric_standard) {
156 setlocale(LC_NUMERIC, "C");
157 PL_numeric_standard = TRUE;
158 PL_numeric_local = FALSE;
162 #endif /* USE_LOCALE_NUMERIC */
166 Perl_set_numeric_local(pTHX)
168 #ifdef USE_LOCALE_NUMERIC
171 if (! PL_numeric_local) {
172 setlocale(LC_NUMERIC, PL_numeric_name);
173 PL_numeric_standard = FALSE;
174 PL_numeric_local = TRUE;
178 #endif /* USE_LOCALE_NUMERIC */
182 * Set up for a new ctype locale.
185 Perl_new_ctype(pTHX_ const char *newctype)
187 #ifdef USE_LOCALE_CTYPE
191 PERL_ARGS_ASSERT_NEW_CTYPE;
193 for (i = 0; i < 256; i++) {
195 PL_fold_locale[i] = toLOWER_LC(i);
196 else if (isLOWER_LC(i))
197 PL_fold_locale[i] = toUPPER_LC(i);
199 PL_fold_locale[i] = i;
202 #endif /* USE_LOCALE_CTYPE */
203 PERL_ARGS_ASSERT_NEW_CTYPE;
204 PERL_UNUSED_ARG(newctype);
209 * Set up for a new collation locale.
212 Perl_new_collate(pTHX_ const char *newcoll)
214 #ifdef USE_LOCALE_COLLATE
218 if (PL_collation_name) {
220 Safefree(PL_collation_name);
221 PL_collation_name = NULL;
223 PL_collation_standard = TRUE;
224 PL_collxfrm_base = 0;
225 PL_collxfrm_mult = 2;
229 if (! PL_collation_name || strNE(PL_collation_name, newcoll)) {
231 Safefree(PL_collation_name);
232 PL_collation_name = stdize_locale(savepv(newcoll));
233 PL_collation_standard = ((*newcoll == 'C' && newcoll[1] == '\0')
234 || strEQ(newcoll, "POSIX"));
237 /* 2: at most so many chars ('a', 'b'). */
238 /* 50: surely no system expands a char more. */
239 #define XFRMBUFSIZE (2 * 50)
240 char xbuf[XFRMBUFSIZE];
241 const Size_t fa = strxfrm(xbuf, "a", XFRMBUFSIZE);
242 const Size_t fb = strxfrm(xbuf, "ab", XFRMBUFSIZE);
243 const SSize_t mult = fb - fa;
244 if (mult < 1 && !(fa == 0 && fb == 0))
245 Perl_croak(aTHX_ "panic: strxfrm() gets absurd - a => %"UVuf", ab => %"UVuf,
247 PL_collxfrm_base = (fa > (Size_t)mult) ? (fa - mult) : 0;
248 PL_collxfrm_mult = mult;
252 #endif /* USE_LOCALE_COLLATE */
256 * Initialize locale awareness.
259 Perl_init_i18nl10n(pTHX_ int printwarn)
263 * 1 = set ok or not applicable,
264 * 0 = fallback to C locale,
265 * -1 = fallback to C locale failed
268 #if defined(USE_LOCALE)
271 #ifdef USE_LOCALE_CTYPE
272 char *curctype = NULL;
273 #endif /* USE_LOCALE_CTYPE */
274 #ifdef USE_LOCALE_COLLATE
275 char *curcoll = NULL;
276 #endif /* USE_LOCALE_COLLATE */
277 #ifdef USE_LOCALE_NUMERIC
279 #endif /* USE_LOCALE_NUMERIC */
281 char * const language = PerlEnv_getenv("LANGUAGE");
283 /* NULL uses the existing already set up locale */
284 const char * const setlocale_init = (PerlEnv_getenv("PERL_SKIP_LOCALE_INIT"))
287 char * const lc_all = PerlEnv_getenv("LC_ALL");
288 char * const lang = PerlEnv_getenv("LANG");
289 bool setlocale_failure = FALSE;
291 #ifdef LOCALE_ENVIRON_REQUIRED
294 * Ultrix setlocale(..., "") fails if there are no environment
295 * variables from which to get a locale name.
302 if (setlocale(LC_ALL, setlocale_init))
305 setlocale_failure = TRUE;
307 if (!setlocale_failure) {
308 # ifdef USE_LOCALE_CTYPE
312 (!done && (lang || PerlEnv_getenv("LC_CTYPE")))
313 ? setlocale_init : NULL)))
314 setlocale_failure = TRUE;
316 curctype = savepv(curctype);
317 # endif /* USE_LOCALE_CTYPE */
318 # ifdef USE_LOCALE_COLLATE
321 setlocale(LC_COLLATE,
322 (!done && (lang || PerlEnv_getenv("LC_COLLATE")))
323 ? setlocale_init : NULL)))
324 setlocale_failure = TRUE;
326 curcoll = savepv(curcoll);
327 # endif /* USE_LOCALE_COLLATE */
328 # ifdef USE_LOCALE_NUMERIC
331 setlocale(LC_NUMERIC,
332 (!done && (lang || PerlEnv_getenv("LC_NUMERIC")))
333 ? setlocale_init : NULL)))
334 setlocale_failure = TRUE;
336 curnum = savepv(curnum);
337 # endif /* USE_LOCALE_NUMERIC */
342 #endif /* !LOCALE_ENVIRON_REQUIRED */
345 if (! setlocale(LC_ALL, setlocale_init))
346 setlocale_failure = TRUE;
349 if (!setlocale_failure) {
350 #ifdef USE_LOCALE_CTYPE
352 if (! (curctype = setlocale(LC_CTYPE, setlocale_init)))
353 setlocale_failure = TRUE;
355 curctype = savepv(curctype);
356 #endif /* USE_LOCALE_CTYPE */
357 #ifdef USE_LOCALE_COLLATE
359 if (! (curcoll = setlocale(LC_COLLATE, setlocale_init)))
360 setlocale_failure = TRUE;
362 curcoll = savepv(curcoll);
363 #endif /* USE_LOCALE_COLLATE */
364 #ifdef USE_LOCALE_NUMERIC
366 if (! (curnum = setlocale(LC_NUMERIC, setlocale_init)))
367 setlocale_failure = TRUE;
369 curnum = savepv(curnum);
370 #endif /* USE_LOCALE_NUMERIC */
373 if (setlocale_failure) {
375 const bool locwarn = (printwarn > 1 ||
377 (!(p = PerlEnv_getenv("PERL_BADLANG")) || atoi(p))));
382 PerlIO_printf(Perl_error_log,
383 "perl: warning: Setting locale failed.\n");
387 PerlIO_printf(Perl_error_log,
388 "perl: warning: Setting locale failed for the categories:\n\t");
389 #ifdef USE_LOCALE_CTYPE
391 PerlIO_printf(Perl_error_log, "LC_CTYPE ");
392 #endif /* USE_LOCALE_CTYPE */
393 #ifdef USE_LOCALE_COLLATE
395 PerlIO_printf(Perl_error_log, "LC_COLLATE ");
396 #endif /* USE_LOCALE_COLLATE */
397 #ifdef USE_LOCALE_NUMERIC
399 PerlIO_printf(Perl_error_log, "LC_NUMERIC ");
400 #endif /* USE_LOCALE_NUMERIC */
401 PerlIO_printf(Perl_error_log, "\n");
405 PerlIO_printf(Perl_error_log,
406 "perl: warning: Please check that your locale settings:\n");
409 PerlIO_printf(Perl_error_log,
410 "\tLANGUAGE = %c%s%c,\n",
411 language ? '"' : '(',
412 language ? language : "unset",
413 language ? '"' : ')');
416 PerlIO_printf(Perl_error_log,
417 "\tLC_ALL = %c%s%c,\n",
419 lc_all ? lc_all : "unset",
422 #if defined(USE_ENVIRON_ARRAY)
425 for (e = environ; *e; e++) {
426 if (strnEQ(*e, "LC_", 3)
427 && strnNE(*e, "LC_ALL=", 7)
428 && (p = strchr(*e, '=')))
429 PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n",
430 (int)(p - *e), *e, p + 1);
434 PerlIO_printf(Perl_error_log,
435 "\t(possibly more locale environment variables)\n");
438 PerlIO_printf(Perl_error_log,
441 lang ? lang : "unset",
444 PerlIO_printf(Perl_error_log,
445 " are supported and installed on your system.\n");
450 if (setlocale(LC_ALL, "C")) {
452 PerlIO_printf(Perl_error_log,
453 "perl: warning: Falling back to the standard locale (\"C\").\n");
458 PerlIO_printf(Perl_error_log,
459 "perl: warning: Failed to fall back to the standard locale (\"C\").\n");
466 #ifdef USE_LOCALE_CTYPE
467 || !(curctype || setlocale(LC_CTYPE, "C"))
468 #endif /* USE_LOCALE_CTYPE */
469 #ifdef USE_LOCALE_COLLATE
470 || !(curcoll || setlocale(LC_COLLATE, "C"))
471 #endif /* USE_LOCALE_COLLATE */
472 #ifdef USE_LOCALE_NUMERIC
473 || !(curnum || setlocale(LC_NUMERIC, "C"))
474 #endif /* USE_LOCALE_NUMERIC */
478 PerlIO_printf(Perl_error_log,
479 "perl: warning: Cannot fall back to the standard locale (\"C\").\n");
483 #endif /* ! LC_ALL */
485 #ifdef USE_LOCALE_CTYPE
487 curctype = savepv(setlocale(LC_CTYPE, NULL));
488 #endif /* USE_LOCALE_CTYPE */
489 #ifdef USE_LOCALE_COLLATE
491 curcoll = savepv(setlocale(LC_COLLATE, NULL));
492 #endif /* USE_LOCALE_COLLATE */
493 #ifdef USE_LOCALE_NUMERIC
495 curnum = savepv(setlocale(LC_NUMERIC, NULL));
496 #endif /* USE_LOCALE_NUMERIC */
500 #ifdef USE_LOCALE_CTYPE
502 #endif /* USE_LOCALE_CTYPE */
504 #ifdef USE_LOCALE_COLLATE
505 new_collate(curcoll);
506 #endif /* USE_LOCALE_COLLATE */
508 #ifdef USE_LOCALE_NUMERIC
510 #endif /* USE_LOCALE_NUMERIC */
514 #if defined(USE_PERLIO) && defined(USE_LOCALE_CTYPE)
516 /* Set PL_utf8locale to TRUE if using PerlIO _and_
517 the current LC_CTYPE locale is UTF-8.
518 If PL_utf8locale and PL_unicode (set by -C or by $ENV{PERL_UNICODE})
519 are true, perl.c:S_parse_body() will turn on the PerlIO :utf8 layer
520 on STDIN, STDOUT, STDERR, _and_ the default open discipline.
522 PL_utf8locale = is_cur_LC_category_utf8(LC_CTYPE);
524 /* Set PL_unicode to $ENV{PERL_UNICODE} if using PerlIO.
525 This is an alternative to using the -C command line switch
526 (the -C if present will override this). */
528 const char *p = PerlEnv_getenv("PERL_UNICODE");
529 PL_unicode = p ? parse_unicode_opts(&p) : 0;
530 if (PL_unicode & PERL_UNICODE_UTF8CACHEASSERT_FLAG)
535 #ifdef USE_LOCALE_CTYPE
537 #endif /* USE_LOCALE_CTYPE */
538 #ifdef USE_LOCALE_COLLATE
540 #endif /* USE_LOCALE_COLLATE */
541 #ifdef USE_LOCALE_NUMERIC
543 #endif /* USE_LOCALE_NUMERIC */
545 #endif /* USE_LOCALE */
550 #ifdef USE_LOCALE_COLLATE
553 * mem_collxfrm() is a bit like strxfrm() but with two important
554 * differences. First, it handles embedded NULs. Second, it allocates
555 * a bit more memory than needed for the transformed data itself.
556 * The real transformed data begins at offset sizeof(collationix).
557 * Please see sv_collxfrm() to see how this is used.
561 Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen)
565 STRLEN xAlloc, xin, xout; /* xalloc is a reserved word in VC */
567 PERL_ARGS_ASSERT_MEM_COLLXFRM;
569 /* the first sizeof(collationix) bytes are used by sv_collxfrm(). */
570 /* the +1 is for the terminating NUL. */
572 xAlloc = sizeof(PL_collation_ix) + PL_collxfrm_base + (PL_collxfrm_mult * len) + 1;
573 Newx(xbuf, xAlloc, char);
577 *(U32*)xbuf = PL_collation_ix;
578 xout = sizeof(PL_collation_ix);
579 for (xin = 0; xin < len; ) {
583 xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
584 if (xused >= PERL_INT_MAX)
586 if ((STRLEN)xused < xAlloc - xout)
588 xAlloc = (2 * xAlloc) + 1;
589 Renew(xbuf, xAlloc, char);
594 xin += strlen(s + xin) + 1;
597 /* Embedded NULs are understood but silently skipped
598 * because they make no sense in locale collation. */
602 *xlen = xout - sizeof(PL_collation_ix);
611 #endif /* USE_LOCALE_COLLATE */
616 S_is_cur_LC_category_utf8(pTHX_ int category)
618 /* Returns TRUE if the current locale for 'category' is UTF-8; FALSE
619 * otherwise. 'category' may not be LC_ALL. If the platform doesn't have
620 * nl_langinfo(), this employs a heuristic, which hence could give the
621 * wrong result. It errs on the side of not being a UTF-8 locale. */
623 char *save_input_locale = NULL;
627 assert(category != LC_ALL);
630 /* First dispose of the trivial cases */
631 save_input_locale = stdize_locale(setlocale(category, NULL));
632 if (! save_input_locale) {
633 return FALSE; /* XXX maybe should croak */
635 if ((*save_input_locale == 'C' && save_input_locale[1] == '\0')
636 || strEQ(save_input_locale, "POSIX"))
641 save_input_locale = savepv(save_input_locale);
643 #if defined(HAS_NL_LANGINFO) && defined(CODESET) && defined(USE_LOCALE_CTYPE)
645 { /* Next try nl_langinfo if available */
647 char *save_ctype_locale = NULL;
648 char *codeset = NULL;
650 if (category != LC_CTYPE) { /* nl_langinfo works only on LC_CTYPE */
652 /* Get the current LC_CTYPE locale */
653 save_ctype_locale = stdize_locale(savepv(setlocale(LC_CTYPE, NULL)));
654 if (! save_ctype_locale) {
655 goto cant_use_nllanginfo;
658 /* If LC_CTYPE and the desired category use the same locale, this
659 * means that finding the value for LC_CTYPE is the same as finding
660 * the value for the desired category. Otherwise, switch LC_CTYPE
661 * to the desired category's locale */
662 if (strEQ(save_ctype_locale, save_input_locale)) {
663 Safefree(save_ctype_locale);
664 save_ctype_locale = NULL;
666 else if (! setlocale(LC_CTYPE, save_input_locale)) {
667 Safefree(save_ctype_locale);
668 goto cant_use_nllanginfo;
672 /* Here the current LC_CTYPE is set to the locale of the category whose
673 * information is desired. This means that nl_langinfo() should give
674 * the correct results */
675 codeset = savepv(nl_langinfo(CODESET));
679 /* If we switched LC_CTYPE, switch back */
680 if (save_ctype_locale) {
681 setlocale(LC_CTYPE, save_ctype_locale);
682 Safefree(save_ctype_locale);
685 is_utf8 = foldEQ(codeset, STR_WITH_LEN("UTF-8"))
686 || foldEQ(codeset, STR_WITH_LEN("UTF8"));
689 Safefree(save_input_locale);
696 #endif /* HAS_NL_LANGINFO etc */
698 /* nl_langinfo not available or failed somehow. Look at the locale name to
699 * see if it matches qr/UTF -? 8 /ix */
701 final_pos = strlen(save_input_locale) - 1;
702 if (final_pos >= 3) {
703 char *name = save_input_locale;
705 /* Find next 'U' or 'u' and look from there */
706 while ((name += strcspn(name, "Uu") + 1)
707 <= save_input_locale + final_pos - 2)
709 if (toFOLD(*(name)) != 't'
710 || toFOLD(*(name + 1)) != 'f')
715 if (*(name) == '-') {
716 if ((name > save_input_locale + final_pos - 1)) {
721 if (*(name) == '8') {
722 Safefree(save_input_locale);
729 /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx */
731 && *(save_input_locale + final_pos - 0) == '1'
732 && *(save_input_locale + final_pos - 1) == '0'
733 && *(save_input_locale + final_pos - 2) == '0'
734 && *(save_input_locale + final_pos - 3) == '5'
735 && *(save_input_locale + final_pos - 4) == '6')
737 Safefree(save_input_locale);
742 /* Other common encodings are the ISO 8859 series, which aren't UTF-8 */
743 if (instr(save_input_locale, "8859")) {
744 Safefree(save_input_locale);
748 #ifdef HAS_LOCALECONV
750 # ifdef USE_LOCALE_MONETARY
752 /* Here, there is nothing in the locale name to indicate whether the locale
753 * is UTF-8 or not. This "name", the return of setlocale(), is actually
754 * defined to be opaque, so we can't really rely on the absence of various
755 * substrings in the name to indicate its UTF-8ness. Look at the locale's
756 * currency symbol. Often that will be in the native script, and if the
757 * symbol isn't in UTF-8, we know that the locale isn't. If it is
758 * non-ASCII UTF-8, we infer that the locale is too.
759 * To do this, like above for LC_CTYPE, we first set LC_MONETARY to the
760 * locale of the desired category, if it isn't that locale already */
763 char *save_monetary_locale = NULL;
764 bool illegal_utf8 = FALSE;
765 bool only_ascii = FALSE;
766 const struct lconv* const lc = localeconv();
768 if (category != LC_MONETARY) {
770 save_monetary_locale = stdize_locale(savepv(setlocale(LC_MONETARY,
772 if (! save_monetary_locale) {
773 goto cant_use_monetary;
776 if (strNE(save_monetary_locale, save_input_locale)) {
777 if (! setlocale(LC_MONETARY, save_input_locale)) {
778 Safefree(save_monetary_locale);
779 goto cant_use_monetary;
784 /* Here the current LC_MONETARY is set to the locale of the category
785 * whose information is desired. */
787 if (lc && lc->currency_symbol) {
788 if (! is_utf8_string((U8 *) lc->currency_symbol, 0)) {
791 else if (is_ascii_string((U8 *) lc->currency_symbol, 0)) {
796 /* If we changed it, restore LC_MONETARY to its original locale */
797 if (save_monetary_locale) {
798 setlocale(LC_MONETARY, save_monetary_locale);
799 Safefree(save_monetary_locale);
802 Safefree(save_input_locale);
804 /* It isn't a UTF-8 locale if the symbol is not legal UTF-8; otherwise
805 * assume the locale is UTF-8 if and only if the symbol is non-ascii
806 * UTF-8. (We can't really tell if the locale is UTF-8 or not if the
807 * symbol is just a '$', so we err on the side of it not being UTF-8)
809 return (illegal_utf8)
816 # endif /* USE_LOCALE_MONETARY */
817 #endif /* HAS_LOCALECONV */
819 #if 0 && defined(HAS_STRERROR) && defined(USE_LOCALE_MESSAGES)
821 /* This code is ifdefd out because it was found to not be necessary in testing
822 * on our dromedary test machine, which has over 700 locales. There, looking
823 * at just the currency symbol gave essentially the same results as doing this
824 * extra work. Executing this also caused segfaults in miniperl. I left it in
825 * so as to avoid rewriting it if real-world experience indicates that
826 * dromedary is an outlier. Essentially, instead of returning abpve if we
827 * haven't found illegal utf8, we continue on and examine all the strerror()
828 * messages on the platform for utf8ness. If all are ASCII, we still don't
829 * know the answer; but otherwise we have a pretty good indication of the
830 * utf8ness. The reason this doesn't necessarily help much is that the
831 * messages may not have been translated into the locale. The currency symbol
832 * is much more likely to have been translated. The code below would need to
833 * be altered somewhat to just be a continuation of testing the currency
836 unsigned int failures = 0, non_ascii = 0;
837 char *save_messages_locale = NULL;
839 /* Like above for LC_CTYPE, we set LC_MESSAGES to the locale of the
840 * desired category, if it isn't that locale already */
842 if (category != LC_MESSAGES) {
844 save_messages_locale = stdize_locale(savepv(setlocale(LC_MESSAGES,
846 if (! save_messages_locale) {
847 goto cant_use_messages;
850 if (strEQ(save_messages_locale, save_input_locale)) {
851 Safefree(save_input_locale);
853 else if (! setlocale(LC_MESSAGES, save_input_locale)) {
854 Safefree(save_messages_locale);
855 goto cant_use_messages;
859 /* Here the current LC_MESSAGES is set to the locale of the category
860 * whose information is desired. Look through all the messages */
863 #ifdef HAS_SYS_ERRLIST
868 const U8* const errmsg = (U8 *) Strerror(e) ;
871 if (! is_utf8_string(errmsg, 0)) {
875 else if (! is_ascii_string(errmsg, 0)) {
880 /* And, if we changed it, restore LC_MESSAGES to its original locale */
881 if (save_messages_locale) {
882 setlocale(LC_MESSAGES, save_messages_locale);
883 Safefree(save_messages_locale);
886 /* Any non-UTF-8 message means not a UTF-8 locale; if all are valid,
887 * any non-ascii means it is one; otherwise we assume it isn't */
888 return (failures) ? FALSE : non_ascii;
895 Safefree(save_input_locale);
903 * c-indentation-style: bsd
905 * indent-tabs-mode: nil
908 * ex: set ts=8 sts=4 sw=4 et: