From: Michihiro NAKAJIMA Date: Fri, 15 Apr 2011 09:53:13 +0000 (-0400) Subject: Use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv. X-Git-Tag: v3.0.0a~452 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89032bfda7aa7e63cccbb47894857ac3b85a5049;p=thirdparty%2Flibarchive.git Use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv. The charset name which nl_langinfo(CODESET) returns is dependent on the platform and so GNU libiconv will not recognize the charset name on some platform. It is the same as you pass an empty name "" to iconv, but that is GNU libiconv specific function although FreeBSD iconv allow the empty name. I think locale_charset is better than use of "" because It is easy to know what charset is current when debugging. SVN-Revision: 3234 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ae50853..9728b039b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -515,6 +515,21 @@ IF(ICONV_INCLUDE_DIR) ENDIF(HAVE_NONPOSIX_ICONV_IN_LIBC) ENDIF(HAVE_POSIX_ICONV_IN_LIBC) ENDIF(ICONV_INCLUDE_DIR) +# +IF(HAVE_POSIX_ICONV_IN_LIBICONV) + CHECK_INCLUDE_FILES("localcharset.h" HAVE_LOCALCHARSET_H) + CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET) + IF(NOT HAVE_LOCALE_CHARSET) + FIND_LIBRARY(LIBCHARSET_PATH charset) + IF(LIBCHARSET_PATH) + SET(CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_PATH}) + CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET) + IF(HAVE_LOCALE_CHARSET) + LIST(APPEND ADDITIONAL_LIBS ${LIBCHARSET_PATH}) + ENDIF(HAVE_LOCALE_CHARSET) + ENDIF(LIBCHARSET_PATH) + ENDIF(NOT HAVE_LOCALE_CHARSET) +ENDIF(HAVE_POSIX_ICONV_IN_LIBICONV) # # Find Libxml2 diff --git a/configure.ac b/configure.ac index e6d809935..32ec8beb9 100644 --- a/configure.ac +++ b/configure.ac @@ -238,6 +238,17 @@ AC_ARG_WITH([iconv], if test "x$with_iconv" != "xno"; then AC_CHECK_HEADERS([iconv.h]) AM_ICONV + if test "x$am_cv_lib_iconv" != "xno"; then + AC_CHECK_HEADERS([localcharset.h]) + am_save_LIBS="$LIBS" + LIBS="${LIBS} ${LIBICONV}" + AC_CHECK_FUNCS([locale_charset]) + LIBS="${am_save_LIBS}" + if test "x$ac_cv_func_locale_charset" != "xyes"; then + # If locale_charset() is not in libiconv, we have to find libcharset. + AC_CHECK_LIB(charset,locale_charset) + fi + fi fi AC_ARG_WITH([lzma], diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index d7fd9f42c..00f2e64b1 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -45,6 +45,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33 #ifdef HAVE_LANGINFO_H #include #endif +#ifdef HAVE_LOCALCHARSET_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -303,12 +306,18 @@ archive_wstrappend_wchar(struct archive_wstring *as, wchar_t c) * But iconv on Mac OS 10.6 doesn't seem to handle this correctly; * on that system, we have to explicitly call nl_langinfo() * to get the right name. Not sure about other platforms. + * + * NOTE: GNU libiconv does not recognize the character-set name + * which some platform nl_langinfo(CODESET) returns, so we should + * use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv. */ static const char * default_iconv_charset(const char *charset) { if (charset != NULL && charset[0] != '\0') return charset; -#if HAVE_NL_LANGINFO +#if HAVE_LOCALE_CHARSET + return locale_charset(); +#elif HAVE_NL_LANGINFO return nl_langinfo(CODESET); #else return "";