X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Funicodeio.c;h=9f903664392d814ec5f21bcca645499a4d071f4e;hb=488cf84c63fbbffa44143d0ebf56e5a6c26d4383;hp=9948a4eb5761528e25d00c914a90ba5cd352f658;hpb=df0c912c7a316dfb8e9de696fd4953a35ec74868;p=gnulib.git diff --git a/lib/unicodeio.c b/lib/unicodeio.c index 9948a4eb5..9f9036643 100644 --- a/lib/unicodeio.c +++ b/lib/unicodeio.c @@ -1,6 +1,6 @@ /* Unicode character output to streams with locale dependent encoding. - Copyright (C) 2000 Free Software Foundation, Inc. + Copyright (C) 2000, 2001 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published @@ -121,16 +121,14 @@ print_unicode_char (FILE *stream, unsigned int code) if (!initialized) { - extern const char *locale_charset (void); + extern const char *locale_charset PARAMS ((void)); const char *charset = locale_charset (); - is_utf8 = (charset != NULL && !strcmp (charset, UTF8_NAME)); + is_utf8 = !strcmp (charset, UTF8_NAME); #if HAVE_ICONV if (!is_utf8) { - utf8_to_local = (charset != NULL - ? iconv_open (charset, UTF8_NAME) - : (iconv_t)(-1)); + utf8_to_local = iconv_open (charset, UTF8_NAME); if (utf8_to_local == (iconv_t)(-1)) { /* For an unknown encoding, assume ASCII. */ @@ -170,13 +168,21 @@ print_unicode_char (FILE *stream, unsigned int code) outbytesleft = sizeof (outbuf); /* Convert the character from UTF-8 to the locale's charset. */ - res = iconv (utf8_to_local, &inptr, &inbytesleft, &outptr, &outbytesleft); - if (inbytesleft > 0 || res == (size_t)(-1)) + res = iconv (utf8_to_local, + (ICONV_CONST char **)&inptr, &inbytesleft, + &outptr, &outbytesleft); + if (inbytesleft > 0 || res == (size_t)(-1) + /* Irix iconv() inserts a NUL byte if it cannot convert. */ +# if !defined _LIBICONV_VERSION && (defined sgi || defined __sgi) + || (res > 0 && code != 0 && outptr - outbuf == 1 && *outbuf == '\0') +# endif + ) error (1, res == (size_t)(-1) ? errno : 0, _("cannot convert U+%04X to local character set"), code); - /* Avoid glibc-2.1 bug. */ -# if defined _LIBICONV_VERSION || !(__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) + /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ +# if defined _LIBICONV_VERSION \ + || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) /* Get back to the initial shift state. */ res = iconv (utf8_to_local, NULL, NULL, &outptr, &outbytesleft);