diff --git a/configure.ac b/configure.ac index 908fed382..99eb86c3c 100644 --- a/configure.ac +++ b/configure.ac @@ -104,8 +104,9 @@ fi # This mostly helps OS X users, since fink usually installs out of # tree and doesn't update CFLAGS. # +# It also helps FreeBSD which puts libiconv in /usr/local/lib -for i in /usr/pkg /sw /opt /opt/local; do +for i in /usr/pkg /sw /opt /opt/local /usr/local; do AC_MSG_CHECKING([for $i/include include directory]) if test -d $i/include; then diff --git a/env_universal_common.cpp b/env_universal_common.cpp index d80a4d0d1..80ab4a0fa 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -167,6 +167,26 @@ static const char *iconv_wide_names_2[]= } ; +template +class sloppy {}; + +static size_t hack_iconv(iconv_t cd, const char * const* inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ + /* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...) + OS X and Linux this one: size_t iconv (iconv_t, char **...) + AFAIK there's no single type that can be passed as both char ** and const char **. + Therefore, we let C++ figure it out, by providing a struct with an implicit conversion to both char** and const char **. + */ + struct sloppy_char + { + const char * const * t; + operator char** () const { return (char **)t; } + operator const char** () const { return (const char**)t; } + } slop_inbuf = {inbuf}; + + return iconv( cd, slop_inbuf, inbytesleft, outbuf, outbytesleft ); +} + /** Convert utf-8 string to wide string */ @@ -246,7 +266,12 @@ static wchar_t *utf2wcs( const char *in ) return 0; } - nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len ); + /* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...) + OS X and Linux this one: size_t iconv (iconv_t, char **...) + AFAIK there's no single type that can be passed as both char ** and const char **. + So we cast the function pointer instead (!) + */ + nconv = hack_iconv( cd, &in, &in_len, &nout, &out_len ); if (nconv == (size_t) -1) { @@ -280,6 +305,8 @@ static wchar_t *utf2wcs( const char *in ) return out; } + + /** Convert wide string to utf-8 */ @@ -357,7 +384,7 @@ static char *wcs2utf( const wchar_t *in ) return 0; } - nconv = iconv( cd, &char_in, &in_len, &nout, &out_len ); + nconv = hack_iconv( cd, &char_in, &in_len, &nout, &out_len ); if (nconv == (size_t) -1)