From 1a867685a07dd77c295ab8f75f605669f3ce9034 Mon Sep 17 00:00:00 2001 From: Moriyoshi Koizumi Date: Fri, 11 Oct 2002 07:50:47 +0000 Subject: [PATCH] Added ICONV_IMPL and ICONV_VERSION constants. @- Added ICONV_IMPL and ICONV_VERSION constants to iconv extension to @ indicate which iconv implementation is used. (Moriyoshi) --- ext/iconv/config.m4 | 41 ++++++++++++++++++++++++++++++++++------- ext/iconv/iconv.c | 17 +++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index d075046ecd..a6ffe827af 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -8,8 +8,15 @@ PHP_ARG_WITH(iconv, for iconv support, if test "$PHP_ICONV" != "no"; then PHP_SETUP_ICONV(ICONV_SHARED_LIBADD, [ - AC_MSG_CHECKING([if iconv supports errno]) - AC_TRY_RUN([ + iconv_avail="yes"; + ],[ + iconv_avail="no"; + ]) + + if test "$iconv_avail" != "no"; then + + AC_MSG_CHECKING([if iconv supports errno]) + AC_TRY_RUN([ #define LIBICONV_PLUG #include #include @@ -39,17 +46,37 @@ int main() { ],[ AC_MSG_RESULT(yes) PHP_DEFINE([ICONV_SUPPORTS_ERRNO],1) - AC_DEFINE(ICONV_SUPPORTS_ERRNO,1,[Whether iconv supports error no or not]) + AC_DEFINE([ICONV_SUPPORTS_ERRNO],1,[Whether iconv supports error no or not]) ],[ PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0) - AC_DEFINE(ICONV_SUPPORTS_ERRNO,0,[Whether iconv supports error no or not]) + AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not]) AC_MSG_RESULT(no) ]) + if test -z "$iconv_lib_name"; then + AC_MSG_CHECKING([if iconv is glibc's]) + AC_TRY_COMPILE([#include ],[void __gconv(); int main() { __gconv(); } ],[ + AC_MSG_RESULT(yes) + PHP_DEFINE([ICONV_IMPL],["glibc"]) + AC_DEFINE([ICONV_IMPL],["glibc"],[Which iconv implementation to use]) +],[ + AC_MSG_RESULT(no) +]) + else + case "$iconv_lib_name" in + iconv [)] + PHP_DEFINE([ICONV_IMPL],["libiconv"]) + AC_DEFINE([ICONV_IMPL],["libiconv"],[Which iconv implementation to use]) + ;; + giconv [)] + PHP_DEFINE([ICONV_IMPL],["giconv"]) + AC_DEFINE([ICONV_IMPL],["giconv"],[Which iconv implementation to use]) + ;; + esac + fi PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared) PHP_SUBST(ICONV_SHARED_LIBADD) - ], [ + else AC_MSG_ERROR(Please reinstall the iconv library.) - ]) - + fi fi diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index eada3025af..b7e56710de 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -106,8 +106,25 @@ static void php_iconv_init_globals(zend_iconv_globals *iconv_globals) PHP_MINIT_FUNCTION(miconv) { + char *impl_name = "unknown"; + char *version = ""; + ZEND_INIT_MODULE_GLOBALS(iconv, php_iconv_init_globals, NULL); REGISTER_INI_ENTRIES(); + +#if HAVE_LIBICONV + { + static char buf[16]; + impl_name = "libiconv"; + snprintf( buf, sizeof(buf), "%d.%d", ((_libiconv_version >> 8) & 0x0f), + (_libiconv_version & 0x0f) ); + version = buf; + } +#endif + + REGISTER_STRING_CONSTANT( "ICONV_IMPL", ICONV_IMPL, CONST_CS | CONST_PERSISTENT ); + REGISTER_STRING_CONSTANT( "ICONV_VERSION", version, CONST_CS | CONST_PERSISTENT ); + return SUCCESS; } -- 2.40.0