+#if 0 && defined(HAS_STRERROR) && defined(USE_LOCALE_MESSAGES)
+
+/* This code is ifdefd out because it was found to not be necessary in testing
+ * on our dromedary test machine, which has over 700 locales. There, looking
+ * at just the currency symbol gave essentially the same results as doing this
+ * extra work. Executing this also caused segfaults in miniperl. I left it in
+ * so as to avoid rewriting it if real-world experience indicates that
+ * dromedary is an outlier. Essentially, instead of returning abpve if we
+ * haven't found illegal utf8, we continue on and examine all the strerror()
+ * messages on the platform for utf8ness. If all are ASCII, we still don't
+ * know the answer; but otherwise we have a pretty good indication of the
+ * utf8ness. The reason this doesn't necessarily help much is that the
+ * messages may not have been translated into the locale. The currency symbol
+ * is much more likely to have been translated. The code below would need to
+ * be altered somewhat to just be a continuation of testing the currency
+ * symbol. */
+ int e;
+ unsigned int failures = 0, non_ascii = 0;
+ char *save_messages_locale = NULL;
+
+ /* Like above for LC_CTYPE, we set LC_MESSAGES to the locale of the
+ * desired category, if it isn't that locale already */
+
+ if (category != LC_MESSAGES) {
+
+ save_messages_locale = stdize_locale(savepv(setlocale(LC_MESSAGES,
+ NULL)));
+ if (! save_messages_locale) {
+ goto cant_use_messages;
+ }
+
+ if (strEQ(save_messages_locale, save_input_locale)) {
+ Safefree(save_input_locale);
+ }
+ else if (! setlocale(LC_MESSAGES, save_input_locale)) {
+ Safefree(save_messages_locale);
+ goto cant_use_messages;
+ }
+ }
+
+ /* Here the current LC_MESSAGES is set to the locale of the category
+ * whose information is desired. Look through all the messages */
+
+ for (e = 0;
+#ifdef HAS_SYS_ERRLIST
+ e <= sys_nerr
+#endif
+ ; e++)
+ {
+ const U8* const errmsg = (U8 *) Strerror(e) ;
+ if (!errmsg)
+ break;
+ if (! is_utf8_string(errmsg, 0)) {
+ failures++;
+ break;
+ }
+ else if (! is_ascii_string(errmsg, 0)) {
+ non_ascii++;
+ }
+ }
+
+ /* And, if we changed it, restore LC_MESSAGES to its original locale */
+ if (save_messages_locale) {
+ setlocale(LC_MESSAGES, save_messages_locale);
+ Safefree(save_messages_locale);
+ }
+
+ /* Any non-UTF-8 message means not a UTF-8 locale; if all are valid,
+ * any non-ascii means it is one; otherwise we assume it isn't */
+ return (failures) ? FALSE : non_ascii;
+
+ }
+ cant_use_messages:
+
+#endif
+
+#endif /* the code that is compiled when no nl_langinfo */
+
+ /* As a last resort, look at the locale name to see if it matches
+ * qr/UTF -? * 8 /ix, or some other common locale names. This "name", the
+ * return of setlocale(), is actually defined to be opaque, so we can't
+ * really rely on the absence of various substrings in the name to indicate
+ * its UTF-8ness, but if it has UTF8 in the name, it is extremely likely to
+ * be a UTF-8 locale. Similarly for the other common names */
+
+ final_pos = strlen(save_input_locale) - 1;
+ if (final_pos >= 3) {
+ char *name = save_input_locale;
+
+ /* Find next 'U' or 'u' and look from there */
+ while ((name += strcspn(name, "Uu") + 1)
+ <= save_input_locale + final_pos - 2)
+ {
+ if (toFOLD(*(name)) != 't'
+ || toFOLD(*(name + 1)) != 'f')
+ {
+ continue;
+ }
+ name += 2;
+ if (*(name) == '-') {
+ if ((name > save_input_locale + final_pos - 1)) {
+ break;
+ }
+ name++;
+ }
+ if (*(name) == '8') {
+ Safefree(save_input_locale);
+ DEBUG_L(PerlIO_printf(Perl_debug_log,
+ "Locale %s ends with UTF-8 in name\n",
+ save_input_locale));
+ return TRUE;
+ }
+ }
+ DEBUG_L(PerlIO_printf(Perl_debug_log,
+ "Locale %s doesn't end with UTF-8 in name\n",
+ save_input_locale));
+ }
+
+#ifdef WIN32
+ /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx */
+ if (final_pos >= 4
+ && *(save_input_locale + final_pos - 0) == '1'
+ && *(save_input_locale + final_pos - 1) == '0'
+ && *(save_input_locale + final_pos - 2) == '0'
+ && *(save_input_locale + final_pos - 3) == '5'
+ && *(save_input_locale + final_pos - 4) == '6')
+ {
+ 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. But
+ * since we are about to return FALSE anyway, there is no point in doing
+ * this extra work */
+#if 0
+ if (instr(save_input_locale, "8859")) {
+ 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;
+ }
+#endif