patch from Roumen Petrov to detect if iconv() needs a const for the second

* config.h.in configure.in encoding.c: patch from Roumen Petrov
  to detect if iconv() needs a const for the second parameter
Daniel

svn path=/trunk/; revision=3693
diff --git a/ChangeLog b/ChangeLog
index d47d571..55ce059 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Feb 15 08:45:32 CET 2008 Daniel Veillard <daniel@veillard.com>
+
+	* config.h.in configure.in encoding.c: patch from Roumen Petrov
+	  to detect if iconv() needs a const for the second parameter
+
 Fri Feb 15 08:41:31 CET 2008 Daniel Veillard <daniel@veillard.com>
 
 	* macos/src/XMLTestPrefix2.h win32/Makefile.msvc: EOL cleanups
diff --git a/config.h.in b/config.h.in
index 1dafc10..f8435d4 100644
--- a/config.h.in
+++ b/config.h.in
@@ -246,6 +246,9 @@
 /* Whether __va_copy() is available */
 #undef HAVE___VA_COPY
 
+/* Define as const if the declaration of iconv() needs const. */
+#undef ICONV_CONST
+
 /* Name of package */
 #undef PACKAGE
 
diff --git a/configure.in b/configure.in
index 699232f..f46505c 100644
--- a/configure.in
+++ b/configure.in
@@ -1224,6 +1224,29 @@
 		AC_MSG_RESULT(no)
 		LIBS="${_libs}"
 		LDFLAGS="${_ldflags}"])]))
+
+	if test "$WITH_ICONV" = "1" ; then
+		AC_MSG_CHECKING([for iconv declaration])
+		AC_CACHE_VAL(xml_cv_iconv_arg2, [
+			AC_TRY_COMPILE([#include <stdlib.h>
+#include <iconv.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+#if defined(__STDC__) || defined(__cplusplus)
+size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
+#else
+size_t iconv();
+#endif
+], [], xml_cv_iconv_arg2="", xml_cv_iconv_arg2="const")])
+
+		xml_cv_iconv_decl="extern size_t iconv (iconv_t cd, $xml_cv_iconv_arg2 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"
+		AC_MSG_RESULT([${xml_xxx:-
+	}$xml_cv_iconv_decl])
+		AC_DEFINE_UNQUOTED(ICONV_CONST, $xml_cv_iconv_arg2,
+			[Define as const if the declaration of iconv() needs const.])
+	fi
 fi
 case "$host" in
 	*mingw*) M_LIBS=""
diff --git a/encoding.c b/encoding.c
index 002eeba..ee5ac39 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1703,7 +1703,7 @@
     }
     icv_inlen = *inlen;
     icv_outlen = *outlen;
-    ret = iconv(cd, (char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen);
+    ret = iconv(cd, (ICONV_CONST char **) &icv_in, &icv_inlen, &icv_out, &icv_outlen);
     *inlen -= icv_inlen;
     *outlen -= icv_outlen;
     if ((icv_inlen != 0) || (ret == -1)) {