X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Ficonv_open.m4;h=b062e73b28635eed5a567ba4570eb174f4c415eb;hb=cd78e7369fe57d42e3845ef953c765ed3602ebb4;hp=d6f44fb371da9866d50db8d0878209b1d34961f2;hpb=b2e2010c7c902235b5efb5bd3c6529f61b093aa4;p=gnulib.git diff --git a/m4/iconv_open.m4 b/m4/iconv_open.m4 index d6f44fb37..b062e73b2 100644 --- a/m4/iconv_open.m4 +++ b/m4/iconv_open.m4 @@ -1,5 +1,5 @@ -# iconv_open.m4 serial 6 -dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. +# iconv_open.m4 serial 12 +dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -10,11 +10,13 @@ AC_DEFUN([gl_FUNC_ICONV_OPEN], AC_REQUIRE([AC_CANONICAL_HOST]) AC_REQUIRE([gl_ICONV_H_DEFAULTS]) if test "$am_cv_func_iconv" = yes; then + dnl Provide the override, for the sake of the C++ aliases. + gl_REPLACE_ICONV_H dnl Test whether iconv_open accepts standardized encoding names. dnl We know that GNU libiconv and GNU libc do. AC_EGREP_CPP([gnu_iconv], [ #include - #if defined _LIBICONV_VERSION || defined __GLIBC__ + #if defined _LIBICONV_VERSION || (defined __GLIBC__ && !defined __UCLIBC__) gnu_iconv #endif ], [gl_func_iconv_gnu=yes], [gl_func_iconv_gnu=no]) @@ -50,26 +52,21 @@ AC_DEFUN([gl_FUNC_ICONV_OPEN_UTF], AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles AC_REQUIRE([gl_ICONV_H_DEFAULTS]) if test "$am_cv_func_iconv" = yes; then - if test -n "$am_cv_proto_iconv_arg1"; then - ICONV_CONST="const" - else - ICONV_CONST= - fi - AC_SUBST([ICONV_CONST]) AC_CACHE_CHECK([whether iconv supports conversion between UTF-8 and UTF-{16,32}{BE,LE}], [gl_cv_func_iconv_supports_utf], [ save_LIBS="$LIBS" LIBS="$LIBS $LIBICONV" - AC_TRY_RUN([ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ #include #include #include #include #include -#define ASSERT(expr) if (!(expr)) return 1; int main () { + int result = 0; /* Test conversion from UTF-8 to UTF-16BE with no errors. */ { static const char input[] = @@ -77,25 +74,33 @@ int main () static const char expected[] = "\000J\000a\000p\000a\000n\000e\000s\000e\000 \000(\145\345\147\054\212\236\000)\000 \000[\330\065\335\015\330\065\335\036\330\065\335\055\000]"; iconv_t cd; - char buf[100]; - const char *inptr; - size_t inbytesleft; - char *outptr; - size_t outbytesleft; - size_t res; cd = iconv_open ("UTF-16BE", "UTF-8"); - ASSERT (cd != (iconv_t)(-1)); - inptr = input; - inbytesleft = sizeof (input) - 1; - outptr = buf; - outbytesleft = sizeof (buf); - res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - ASSERT (res == 0 && inbytesleft == 0); - ASSERT (outptr == buf + (sizeof (expected) - 1)); - ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); - ASSERT (iconv_close (cd) == 0); + if (cd == (iconv_t)(-1)) + result |= 1; + else + { + char buf[100]; + const char *inptr; + size_t inbytesleft; + char *outptr; + size_t outbytesleft; + size_t res; + inptr = input; + inbytesleft = sizeof (input) - 1; + outptr = buf; + outbytesleft = sizeof (buf); + res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (!(res == 0 && inbytesleft == 0)) + result |= 1; + else if (!(outptr == buf + (sizeof (expected) - 1))) + result |= 1; + else if (!(memcmp (buf, expected, sizeof (expected) - 1) == 0)) + result |= 1; + else if (!(iconv_close (cd) == 0)) + result |= 1; + } } /* Test conversion from UTF-8 to UTF-16LE with no errors. */ { @@ -104,25 +109,33 @@ int main () static const char expected[] = "J\000a\000p\000a\000n\000e\000s\000e\000 \000(\000\345\145\054\147\236\212)\000 \000[\000\065\330\015\335\065\330\036\335\065\330\055\335]\000"; iconv_t cd; - char buf[100]; - const char *inptr; - size_t inbytesleft; - char *outptr; - size_t outbytesleft; - size_t res; cd = iconv_open ("UTF-16LE", "UTF-8"); - ASSERT (cd != (iconv_t)(-1)); - inptr = input; - inbytesleft = sizeof (input) - 1; - outptr = buf; - outbytesleft = sizeof (buf); - res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - ASSERT (res == 0 && inbytesleft == 0); - ASSERT (outptr == buf + (sizeof (expected) - 1)); - ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); - ASSERT (iconv_close (cd) == 0); + if (cd == (iconv_t)(-1)) + result |= 2; + else + { + char buf[100]; + const char *inptr; + size_t inbytesleft; + char *outptr; + size_t outbytesleft; + size_t res; + inptr = input; + inbytesleft = sizeof (input) - 1; + outptr = buf; + outbytesleft = sizeof (buf); + res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (!(res == 0 && inbytesleft == 0)) + result |= 2; + else if (!(outptr == buf + (sizeof (expected) - 1))) + result |= 2; + else if (!(memcmp (buf, expected, sizeof (expected) - 1) == 0)) + result |= 2; + else if (!(iconv_close (cd) == 0)) + result |= 2; + } } /* Test conversion from UTF-8 to UTF-32BE with no errors. */ { @@ -131,25 +144,33 @@ int main () static const char expected[] = "\000\000\000J\000\000\000a\000\000\000p\000\000\000a\000\000\000n\000\000\000e\000\000\000s\000\000\000e\000\000\000 \000\000\000(\000\000\145\345\000\000\147\054\000\000\212\236\000\000\000)\000\000\000 \000\000\000[\000\001\325\015\000\001\325\036\000\001\325\055\000\000\000]"; iconv_t cd; - char buf[100]; - const char *inptr; - size_t inbytesleft; - char *outptr; - size_t outbytesleft; - size_t res; cd = iconv_open ("UTF-32BE", "UTF-8"); - ASSERT (cd != (iconv_t)(-1)); - inptr = input; - inbytesleft = sizeof (input) - 1; - outptr = buf; - outbytesleft = sizeof (buf); - res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - ASSERT (res == 0 && inbytesleft == 0); - ASSERT (outptr == buf + (sizeof (expected) - 1)); - ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); - ASSERT (iconv_close (cd) == 0); + if (cd == (iconv_t)(-1)) + result |= 4; + else + { + char buf[100]; + const char *inptr; + size_t inbytesleft; + char *outptr; + size_t outbytesleft; + size_t res; + inptr = input; + inbytesleft = sizeof (input) - 1; + outptr = buf; + outbytesleft = sizeof (buf); + res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (!(res == 0 && inbytesleft == 0)) + result |= 4; + else if (!(outptr == buf + (sizeof (expected) - 1))) + result |= 4; + else if (!(memcmp (buf, expected, sizeof (expected) - 1) == 0)) + result |= 4; + else if (!(iconv_close (cd) == 0)) + result |= 4; + } } /* Test conversion from UTF-8 to UTF-32LE with no errors. */ { @@ -158,25 +179,33 @@ int main () static const char expected[] = "J\000\000\000a\000\000\000p\000\000\000a\000\000\000n\000\000\000e\000\000\000s\000\000\000e\000\000\000 \000\000\000(\000\000\000\345\145\000\000\054\147\000\000\236\212\000\000)\000\000\000 \000\000\000[\000\000\000\015\325\001\000\036\325\001\000\055\325\001\000]\000\000\000"; iconv_t cd; - char buf[100]; - const char *inptr; - size_t inbytesleft; - char *outptr; - size_t outbytesleft; - size_t res; cd = iconv_open ("UTF-32LE", "UTF-8"); - ASSERT (cd != (iconv_t)(-1)); - inptr = input; - inbytesleft = sizeof (input) - 1; - outptr = buf; - outbytesleft = sizeof (buf); - res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - ASSERT (res == 0 && inbytesleft == 0); - ASSERT (outptr == buf + (sizeof (expected) - 1)); - ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); - ASSERT (iconv_close (cd) == 0); + if (cd == (iconv_t)(-1)) + result |= 8; + else + { + char buf[100]; + const char *inptr; + size_t inbytesleft; + char *outptr; + size_t outbytesleft; + size_t res; + inptr = input; + inbytesleft = sizeof (input) - 1; + outptr = buf; + outbytesleft = sizeof (buf); + res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (!(res == 0 && inbytesleft == 0)) + result |= 8; + else if (!(outptr == buf + (sizeof (expected) - 1))) + result |= 8; + else if (!(memcmp (buf, expected, sizeof (expected) - 1) == 0)) + result |= 8; + else if (!(iconv_close (cd) == 0)) + result |= 8; + } } /* Test conversion from UTF-16BE to UTF-8 with no errors. This test fails on NetBSD 3.0. */ @@ -186,28 +215,38 @@ int main () static const char expected[] = "Japanese (\346\227\245\346\234\254\350\252\236) [\360\235\224\215\360\235\224\236\360\235\224\255]"; iconv_t cd; - char buf[100]; - const char *inptr; - size_t inbytesleft; - char *outptr; - size_t outbytesleft; - size_t res; cd = iconv_open ("UTF-8", "UTF-16BE"); - ASSERT (cd != (iconv_t)(-1)); - inptr = input; - inbytesleft = sizeof (input) - 1; - outptr = buf; - outbytesleft = sizeof (buf); - res = iconv (cd, - (ICONV_CONST char **) &inptr, &inbytesleft, - &outptr, &outbytesleft); - ASSERT (res == 0 && inbytesleft == 0); - ASSERT (outptr == buf + (sizeof (expected) - 1)); - ASSERT (memcmp (buf, expected, sizeof (expected) - 1) == 0); - ASSERT (iconv_close (cd) == 0); + if (cd == (iconv_t)(-1)) + result |= 16; + else + { + char buf[100]; + const char *inptr; + size_t inbytesleft; + char *outptr; + size_t outbytesleft; + size_t res; + inptr = input; + inbytesleft = sizeof (input) - 1; + outptr = buf; + outbytesleft = sizeof (buf); + res = iconv (cd, + (ICONV_CONST char **) &inptr, &inbytesleft, + &outptr, &outbytesleft); + if (!(res == 0 && inbytesleft == 0)) + result |= 16; + else if (!(outptr == buf + (sizeof (expected) - 1))) + result |= 16; + else if (!(memcmp (buf, expected, sizeof (expected) - 1) == 0)) + result |= 16; + else if (!(iconv_close (cd) == 0)) + result |= 16; + } } - return 0; -}], [gl_cv_func_iconv_supports_utf=yes], [gl_cv_func_iconv_supports_utf=no], + return result; +}]])], + [gl_cv_func_iconv_supports_utf=yes], + [gl_cv_func_iconv_supports_utf=no], [ dnl We know that GNU libiconv, GNU libc, and Solaris >= 9 do. dnl OSF/1 5.1 has these encodings, but inserts a BOM in the "to"