Simplify "wchar_t" handling on Cygwin 1.7.x.
diff --git a/ChangeLog b/ChangeLog
index df81fd3..3d867c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-01-29  Corinna Vinschen  <corinna-cygwin@cygwin.com>
+            Bruno Haible  <bruno@clisp.org>
+
+	Simplify "wchar_t" handling on Cygwin 1.7.x.
+	* lib/iconv.c (iconv_canonicalize): On Cygwin >= 1.7, map
+	ei_local_wchar_t to ei_utf16le or ei_utf16be, not ei_ucs2internal.
+	* lib/iconv_open1.h: Likewise.
+	Rationale: <http://cygwin.com/ml/cygwin/2011-01/msg00410.html>.
+
 2011-01-29  Bruno Haible  <bruno@clisp.org>
 
 	Adjust the meaning of "wchar_t" on native Windows systems.
diff --git a/lib/iconv.c b/lib/iconv.c
index 977e771..3785296 100644
--- a/lib/iconv.c
+++ b/lib/iconv.c
@@ -25,6 +25,10 @@
 #include "config.h"
 #include "localcharset.h"
 
+#ifdef __CYGWIN__
+#include <cygwin/version.h>
+#endif
+
 #if ENABLE_EXTRA
 /*
  * Consider all system dependent encodings, for any system,
@@ -549,9 +553,9 @@
     }
     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, where we know that it
-         is UTF-16.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+         This is also the case on native Woe32 systems and Cygwin >= 1.7, where
+         we know that it is UTF-16.  */
+#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || (defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007)
       if (sizeof(wchar_t) == 4) {
         index = ei_ucs4internal;
         break;
diff --git a/lib/iconv_open1.h b/lib/iconv_open1.h
index ce1a576..acee5a4 100644
--- a/lib/iconv_open1.h
+++ b/lib/iconv_open1.h
@@ -97,9 +97,9 @@
     }
     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, where we know that it
-         is UTF-16.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+         This is also the case on native Woe32 systems and Cygwin >= 1.7, where
+         we know that it is UTF-16.  */
+#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || (defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007)
       if (sizeof(wchar_t) == 4) {
         to_index = ei_ucs4internal;
         break;
@@ -187,9 +187,9 @@
     }
     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, where we know that it
-         is UTF-16.  */
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+         This is also the case on native Woe32 systems and Cygwin >= 1.7, where
+         we know that it is UTF-16.  */
+#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || (defined __CYGWIN__ && CYGWIN_VERSION_DLL_MAJOR >= 1007)
       if (sizeof(wchar_t) == 4) {
         from_index = ei_ucs4internal;
         break;