Adjust the meaning of "wchar_t" on native Windows systems.
diff --git a/ChangeLog b/ChangeLog
index 2ba4431..df81fd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-01-29  Bruno Haible  <bruno@clisp.org>
+
+	Adjust the meaning of "wchar_t" on native Windows systems.
+	* lib/iconv.c (iconv_canonicalize): On native Windows, map
+	ei_local_wchar_t to ei_utf16le or ei_utf16be, not ei_ucs2internal.
+	* lib/iconv_open1.h: Likewise.
+	Reported by Corinna Vinschen <corinna-cygwin@cygwin.com>
+	in <http://cygwin.com/ml/cygwin/2011-01/msg00410.html>.
+
 2010-11-23  Bruno Haible  <bruno@clisp.org>
 
 	Implement newer release of BIG5-HKSCS.
diff --git a/lib/iconv.c b/lib/iconv.c
index 5ea9499..977e771 100644
--- a/lib/iconv.c
+++ b/lib/iconv.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1999-2008 Free Software Foundation, Inc.
+ * Copyright (C) 1999-2008, 2011 Free Software Foundation, Inc.
  * This file is part of the GNU LIBICONV Library.
  *
  * The GNU LIBICONV Library is free software; you can redistribute it
@@ -549,8 +549,22 @@
     }
     if (ap->encoding_index == ei_local_wchar_t) {
       /* On systems which define __STDC_ISO_10646__, wchar_t is Unicode.
-         This is also the case on native Woe32 systems.  */
-#if __STDC_ISO_10646__ || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+         This is also the case on native Woe32 systems, where we know that it
+         is UTF-16.  */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+      if (sizeof(wchar_t) == 4) {
+        index = ei_ucs4internal;
+        break;
+      }
+      if (sizeof(wchar_t) == 2) {
+# if WORDS_LITTLEENDIAN
+        index = ei_utf16le;
+# else
+        index = ei_utf16be;
+# endif
+        break;
+      }
+#elif __STDC_ISO_10646__
       if (sizeof(wchar_t) == 4) {
         index = ei_ucs4internal;
         break;
diff --git a/lib/iconv_open1.h b/lib/iconv_open1.h
index 8a77014..ce1a576 100644
--- a/lib/iconv_open1.h
+++ b/lib/iconv_open1.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1999-2008 Free Software Foundation, Inc.
+ * Copyright (C) 1999-2008, 2011 Free Software Foundation, Inc.
  * This file is part of the GNU LIBICONV Library.
  *
  * The GNU LIBICONV Library is free software; you can redistribute it
@@ -97,8 +97,22 @@
     }
     if (ap->encoding_index == ei_local_wchar_t) {
       /* On systems which define __STDC_ISO_10646__, wchar_t is Unicode.
-         This is also the case on native Woe32 systems.  */
-#if __STDC_ISO_10646__ || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+         This is also the case on native Woe32 systems, where we know that it
+         is UTF-16.  */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+      if (sizeof(wchar_t) == 4) {
+        to_index = ei_ucs4internal;
+        break;
+      }
+      if (sizeof(wchar_t) == 2) {
+# if WORDS_LITTLEENDIAN
+        to_index = ei_utf16le;
+# else
+        to_index = ei_utf16be;
+# endif
+        break;
+      }
+#elif __STDC_ISO_10646__
       if (sizeof(wchar_t) == 4) {
         to_index = ei_ucs4internal;
         break;
@@ -173,8 +187,22 @@
     }
     if (ap->encoding_index == ei_local_wchar_t) {
       /* On systems which define __STDC_ISO_10646__, wchar_t is Unicode.
-         This is also the case on native Woe32 systems.  */
-#if __STDC_ISO_10646__ || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+         This is also the case on native Woe32 systems, where we know that it
+         is UTF-16.  */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+      if (sizeof(wchar_t) == 4) {
+        from_index = ei_ucs4internal;
+        break;
+      }
+      if (sizeof(wchar_t) == 2) {
+# if WORDS_LITTLEENDIAN
+        from_index = ei_utf16le;
+# else
+        from_index = ei_utf16be;
+# endif
+        break;
+      }
+#elif __STDC_ISO_10646__
       if (sizeof(wchar_t) == 4) {
         from_index = ei_ucs4internal;
         break;