]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 15 Apr 2011 09:53:13 +0000 (05:53 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 15 Apr 2011 09:53:13 +0000 (05:53 -0400)
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

CMakeLists.txt
configure.ac
libarchive/archive_string.c

index a8ae50853222b5f23d5eaab00a82b51c463ff7d8..9728b039b530944ef5b014ae5e3c4365ca8951c9 100644 (file)
@@ -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
index e6d8099354f3c497eb8a7972dade0e8f8b3c1cef..32ec8beb9ba8c2902300e3f2ba361eb7bf616375 100644 (file)
@@ -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],
index d7fd9f42cf6e443b51f273a3816c6daaae112b26..00f2e64b136af89af38941196a8e4fb7028e90fb 100644 (file)
@@ -45,6 +45,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33
 #ifdef HAVE_LANGINFO_H
 #include <langinfo.h>
 #endif
+#ifdef HAVE_LOCALCHARSET_H
+#include <localcharset.h>
+#endif
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #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 "";