diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 4d0dc36489833..e86f3535a97c4 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -83,6 +83,20 @@ int main(void) { AS_VAR_IF([php_cv_iconv_errno], [yes],, [AC_MSG_FAILURE([The iconv check failed, 'errno' is missing.])]) + dnl iconv on some platforms (NetBSD pre-10, Solaris) may have a non-standard + dnl const input parameter; libiconv may imitate this on those platforms. + AC_CACHE_CHECK([if iconv input parameter is const (non-standard)], [php_cv_iconv_const], + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([ +#include + +size_t iconv(iconv_t cd, const char **src, size_t *srcleft, char **dst, size_t *dstleft); + ])], + [php_cv_iconv_const=const], + [php_cv_iconv_const=non-const])]) + dnl non-const is just used for display, set it back + AS_VAR_IF([php_cv_iconv_const], [non-const], + [php_cv_iconv_const=]) + AC_CACHE_CHECK([if iconv supports //IGNORE], [php_cv_iconv_ignore], [AC_RUN_IFELSE([AC_LANG_SOURCE([ #include @@ -120,7 +134,7 @@ int main(void) { PHP_NEW_EXTENSION([iconv], [iconv.c], [$ext_shared],, - [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1]) + [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DICONV_CONST=$php_cv_iconv_const]) PHP_SUBST([ICONV_SHARED_LIBADD]) PHP_INSTALL_HEADERS([ext/iconv], [php_iconv.h]) fi diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 7bf0c6d23401c..7c812f5af44b4 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -43,11 +43,11 @@ #undef iconv #endif -#if defined(__NetBSD__) || (defined(__sun) && defined(__SVR4)) -// unfortunately, netbsd has still the old non posix conformant signature -// libiconv tends to match the eventual system's iconv too. -#define ICONV_CONST const -#else +/* iconv can have different constiness for src on some platforms; + * this is explained in config.m4. On Windows, it's always non-const, + * but it can be awkward to set that on the command line. Do it here. + */ +#ifndef ICONV_CONST #define ICONV_CONST #endif