$NetBSD: patch-ba,v 1.3 2002/12/30 20:26:08 jmcneill Exp $

--- lib/charconv.c.orig	Thu May 16 20:06:50 2002
+++ lib/charconv.c	Mon Dec 30 15:46:33 2002
@@ -69,6 +69,8 @@
 {
   static char *this_charset = NULL;
   static int local_is_utf8 = 0;
+  unicode_iconv_t t1 = (unicode_iconv_t)(-1);
+  unicode_iconv_t t2 = (unicode_iconv_t)(-1);
 
   if (this_charset) {
     *charset = this_charset;
@@ -98,7 +100,8 @@
 
       if ((*charset == NULL) ||
           (0==strcmp(*charset,"US-ASCII")) ||
-          (0==strcmp(*charset,"ANSI_X3.4-1968"))) {
+          (0==strcmp(*charset,"ANSI_X3.4-1968")) ||
+	  (**charset == '\0')) {
               /* we got basic stupid ASCII here. We use its sane
                  superset instead. Especially since libxml2 doesn't like
                  the pedantic name of ASCII. */
@@ -108,8 +111,25 @@
   }
 
   this_charset = *charset;
-  local_is_utf8 = (*charset) && (0==strcmp(*charset,"UTF-8"));
-  
+  if (*charset) {
+    if (strcmp(*charset, "UTF-8") != 0) {
+      if ((t1 = unicode_iconv_open(*charset, "UTF-8")) == (unicode_iconv_t)(-1)
+         || (t2 = unicode_iconv_open("UTF-8", *charset)) ==
+         (unicode_iconv_t)(-1)) {
+        g_warning("unicode_iconv_open does not understand your charset %s\n%s",
+		   *charset,
+                  "Using UTF-8 as local. Set LC_CTYPE or CHARSET.");
+        local_is_utf8 = 1;
+        *charset = "UTF-8";
+      }
+    } else
+      local_is_utf8 = 1;
+  }
+  if (t1 != (unicode_iconv_t)(-1))
+    unicode_iconv_close(t1);
+  if (t2 != (unicode_iconv_t)(-1))
+    unicode_iconv_close(t2);
+
   return local_is_utf8;
 }
 
