Skip to content

Commit 6905cf2

Browse files
committed
detect IBM iconv implementation and use correct encoding names
1 parent b3a45d4 commit 6905cf2

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

ext/iconv/config.m4

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,24 @@ int main() {
7979
])
8080
fi
8181

82+
if test -z "$iconv_impl_name"; then
83+
AC_MSG_CHECKING([if using IBM iconv])
84+
php_iconv_old_ld="$LDFLAGS"
85+
LDFLAGS="-liconv $LDFLAGS"
86+
AC_TRY_LINK([#include <iconv.h>],[cstoccsid("");],
87+
[
88+
AC_MSG_RESULT(yes)
89+
iconv_impl_name="ibm"
90+
],[
91+
AC_MSG_RESULT(no)
92+
LDFLAGS="$php_iconv_old_ld"
93+
])
94+
fi
95+
8296
echo > ext/iconv/php_have_bsd_iconv.h
8397
echo > ext/iconv/php_have_glibc_iconv.h
8498
echo > ext/iconv/php_have_libiconv.h
99+
echo > ext/iconv/php_have_ibm_iconv.h
85100

86101
case "$iconv_impl_name" in
87102
gnu_libiconv [)]
@@ -104,6 +119,12 @@ int main() {
104119
PHP_DEFINE([PHP_ICONV_IMPL],[\"glibc\"],[ext/iconv])
105120
AC_DEFINE([PHP_ICONV_IMPL],["glibc"],[Which iconv implementation to use])
106121
;;
122+
ibm [)]
123+
PHP_DEFINE([HAVE_IBM_ICONV],1,[ext/iconv])
124+
AC_DEFINE([HAVE_IBM_ICONV],1,[IBM iconv implementation])
125+
PHP_DEFINE([PHP_ICONV_IMPL],[\"IBM iconv\"],[ext/iconv])
126+
AC_DEFINE([PHP_ICONV_IMPL],["IBM iconv"],[Which iconv implementation to use])
127+
;;
107128
esac
108129

109130
AC_MSG_CHECKING([if iconv supports errno])

ext/iconv/iconv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
11021102
goto out;
11031103
}
11041104

1105-
cd_pl = iconv_open("ASCII", enc);
1105+
cd_pl = iconv_open(ICONV_ASCII_ENCODING, enc);
11061106
if (cd_pl == (iconv_t)(-1)) {
11071107
#if ICONV_SUPPORTS_ERRNO
11081108
if (errno == EINVAL) {
@@ -1413,7 +1413,7 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
14131413
*next_pos = NULL;
14141414
}
14151415

1416-
cd_pl = iconv_open(enc, "ASCII");
1416+
cd_pl = iconv_open(enc, ICONV_ASCII_ENCODING);
14171417

14181418
if (cd_pl == (iconv_t)(-1)) {
14191419
#if ICONV_SUPPORTS_ERRNO

ext/iconv/php_iconv.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "ext/iconv/php_have_libiconv.h"
3838
#include "ext/iconv/php_have_glibc_iconv.h"
3939
#include "ext/iconv/php_have_bsd_iconv.h"
40+
#include "ext/iconv/php_have_ibm_iconv.h"
4041
#include "ext/iconv/php_iconv_supports_errno.h"
4142
#include "ext/iconv/php_php_iconv_impl.h"
4243
#include "ext/iconv/php_php_iconv_h_path.h"
@@ -74,9 +75,17 @@ ZEND_END_MODULE_GLOBALS(iconv)
7475
#define ICONVG(v) (iconv_globals.v)
7576
#endif
7677

77-
#define ICONV_INPUT_ENCODING "ISO-8859-1"
78-
#define ICONV_OUTPUT_ENCODING "ISO-8859-1"
79-
#define ICONV_INTERNAL_ENCODING "ISO-8859-1"
78+
#ifdef HAVE_IBM_ICONV
79+
# define ICONV_INPUT_ENCODING "ISO8859-1"
80+
# define ICONV_OUTPUT_ENCODING "ISO8859-1"
81+
# define ICONV_INTERNAL_ENCODING "ISO8859-1"
82+
# define ICONV_ASCII_ENCODING "IBM-850"
83+
#else
84+
# define ICONV_INPUT_ENCODING "ISO-8859-1"
85+
# define ICONV_OUTPUT_ENCODING "ISO-8859-1"
86+
# define ICONV_INTERNAL_ENCODING "ISO-8859-1"
87+
# define ICONV_ASCII_ENCODING "ASCII"
88+
#endif
8089

8190
#ifndef ICONV_CSNMAXLEN
8291
#define ICONV_CSNMAXLEN 64

0 commit comments

Comments
 (0)