From: Moriyoshi Koizumi Date: Sun, 6 Jul 2003 21:11:51 +0000 (+0000) Subject: MFH(r-1.22, r-1.90, r-1.18): avoid miscellaneous conflicts between glibc's X-Git-Tag: php-4.3.3RC2~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e1affd647b21447e753f99e5b8175b22d594bd1;p=php MFH(r-1.22, r-1.90, r-1.18): avoid miscellaneous conflicts between glibc's iconv and libiconv. --- diff --git a/ext/iconv/config.m4 b/ext/iconv/config.m4 index 37f82eb479..5700cc91ad 100644 --- a/ext/iconv/config.m4 +++ b/ext/iconv/config.m4 @@ -15,44 +15,22 @@ if test "$PHP_ICONV" != "no"; then if test "$iconv_avail" != "no"; then iconv_cflags_save="$CFLAGS" - CFLAGS="$CFLAGS $INCLUDES" - AC_MSG_CHECKING([if iconv supports errno]) - AC_TRY_RUN([ -#define LIBICONV_PLUG -#include -#include -#if defined(_LIBICONV_H) -#define icv_open(a, b) libiconv_open(a, b) -#define icv_close(a) libiconv_close(a) -#define icv(a, b, c, d, e) libiconv(a, b, c, d, e) -#else -#define icv_open(a, b) iconv_open(a, b) -#define icv_close(a) iconv_close(a) -#define icv(a, b, c, d, e) iconv(a, b, c, d, e) -#endif + iconv_ldflags_save="$LDFLAGS" -int main() { - iconv_t cd; - cd = icv_open( "*blahblah*", "*blahblah*" ); - if( cd == (iconv_t)(-1) ) { - if( errno == EINVAL ) { - return 0; - } else { - return 1; - } - } - icv_close( cd ); - return 2; -} - ],[ - AC_MSG_RESULT(yes) - PHP_DEFINE([ICONV_SUPPORTS_ERRNO],1) - AC_DEFINE([ICONV_SUPPORTS_ERRNO],1,[Whether iconv supports error no or not]) - ],[ - AC_MSG_RESULT(no) - PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0) - AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not]) - ]) + if test -z "$ICONV_DIR"; then + PHP_ICONV_PREFIX="/usr" + else + PHP_ICONV_PREFIX="$ICONV_DIR" + fi + + CFLAGS="-I$PHP_ICONV_PREFIX/include $CFLAGS" + LDFLAGS="-L$PHP_ICONV_PREFIX/lib $LDFLAGS" + + if test -r $PHP_ICONV_PREFIX/include/giconv.h; then + PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/giconv.h" + else + PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/iconv.h" + fi if test -z "$iconv_lib_name"; then AC_MSG_CHECKING([if iconv is glibc's]) @@ -108,7 +86,39 @@ int main() { ;; esac + AC_MSG_CHECKING([if iconv supports errno]) + AC_TRY_RUN([ +#include <$PHP_ICONV_H_PATH> +#include + +int main() { + iconv_t cd; + cd = iconv_open( "*blahblah*", "*blahblah*" ); + if (cd == (iconv_t)(-1)) { + if (errno == EINVAL) { + return 0; + } else { + return 1; + } + } + iconv_close( cd ); + return 2; +} + ],[ + AC_MSG_RESULT(yes) + PHP_DEFINE([ICONV_SUPPORTS_ERRNO],1) + AC_DEFINE([ICONV_SUPPORTS_ERRNO],1,[Whether iconv supports error no or not]) + ],[ + AC_MSG_RESULT(no) + PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0) + AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not]) + ]) + CFLAGS="$iconv_cflags_save" + LDFLAGS="$iconv_ldflags_save" + + PHP_DEFINE([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>]) + AC_DEFINE_UNQUOTED([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>], [Path to iconv.h]) PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared) PHP_SUBST(ICONV_SHARED_LIBADD) diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 284239c95d..815cfe0de8 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -36,27 +36,16 @@ #ifdef HAVE_ICONV -#ifdef HAVE_GICONV_H -#include -#else -#include +#ifndef PHP_ICONV_H_PATH +#define PHP_ICONV_H_PATH #endif +#include PHP_ICONV_H_PATH + #ifdef HAVE_GLIBC_ICONV #include #endif -#ifdef HAVE_LIBICONV -#define LIBICONV_PLUG -#define icv_open(a, b) libiconv_open(a, b) -#define icv_close(a) libiconv_close(a) -#define icv(a, b, c, d, e) libiconv(a, b, c, d, e) -#else -#define icv_open(a, b) iconv_open(a, b) -#define icv_close(a) iconv_close(a) -#define icv(a, b, c, d, e) iconv(a, (char **) b, c, d, e) -#endif - /* {{{ iconv_functions[] */ function_entry iconv_functions[] = { @@ -213,7 +202,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, in_size = in_len; - cd = icv_open(out_charset, in_charset); + cd = icov_open(out_charset, in_charset); if (cd == (iconv_t)(-1)) { return PHP_ICONV_ERR_UNKNOWN; @@ -222,7 +211,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, out_buffer = (char *) emalloc(out_size + 1); out_p = out_buffer; - result = icv(cd, (const char **) &in_p, &in_size, (char **) + result = iconv(cd, (const char **) &in_p, &in_size, (char **) &out_p, &out_left); if (result == (size_t)(-1)) { @@ -235,7 +224,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, } /* flush the shift-out sequences */ - result = icv(cd, NULL, NULL, &out_p, &out_left); + result = iconv(cd, NULL, NULL, &out_p, &out_left); if (result == (size_t)(-1)) { efree(out_buffer); @@ -246,7 +235,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, out_buffer[*out_len] = '\0'; *out = out_buffer; - icv_close(cd); + iconv_close(cd); return PHP_ICONV_ERR_SUCCESS; @@ -263,7 +252,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, *out = NULL; *out_len = 0; - cd = icv_open(out_charset, in_charset); + cd = iconv_open(out_charset, in_charset); if (cd == (iconv_t)(-1)) { if (errno == EINVAL) { @@ -280,7 +269,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, out_p = out_buf; while (in_left > 0) { - result = icv(cd, (const char **) &in_p, &in_left, (char **) &out_p, &out_left); + result = iconv(cd, (const char **) &in_p, &in_left, (char **) &out_p, &out_left); out_size = bsz - out_left; if (result == (size_t)(-1)) { if (errno == E2BIG && in_left > 0) { @@ -303,7 +292,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, if (result != (size_t)(-1)) { /* flush the shift-out sequences */ for (;;) { - result = icv(cd, NULL, NULL, (char **) &out_p, &out_left); + result = iconv(cd, NULL, NULL, (char **) &out_p, &out_left); out_size = bsz - out_left; if (result != (size_t)(-1)) { @@ -327,7 +316,7 @@ php_iconv_err_t php_iconv_string(const char *in_p, size_t in_len, } } - icv_close(cd); + iconv_close(cd); if (result == (size_t)(-1)) { switch (errno) { diff --git a/ext/iconv/php_iconv.h b/ext/iconv/php_iconv.h index db8c9d65bd..cd6fe83a25 100644 --- a/ext/iconv/php_iconv.h +++ b/ext/iconv/php_iconv.h @@ -35,6 +35,7 @@ #include "php_have_bsd_iconv.h" #include "php_iconv_supports_errno.h" #include "php_php_iconv_impl.h" +#include "php_php_iconv_h_path.h" #endif