glibc/iconvdata/bug-iconv4.c

78 lines
1.4 KiB
C
Raw Permalink Normal View History

#include <errno.h>
#include <iconv.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define UCS_STR "\x4e\x8c" /* EUC-TW 0xa2a2, EUC-JP 0x */
static const char *to_code;
static bool
xiconv (iconv_t cd, int out_size)
{
unsigned char euc[4];
char *inp = (char *) UCS_STR;
* posix/tst-execle1.c (do_test): Add a const. * posix/tst-execle2.c (do_test): Likewise. * posix/transbug.c (run_test): Add some casts. * posix/bug-regex22.c (main): Likewise. * posix/bug-regex5.c (main): Likewise. * wcsmbs/tst-mbsrtowcs.c (main): Likewise. * string/test-strspn.c (do_test, do_random_tests): Likewise. * string/test-strrchr.c (do_test, do_random_tests): Likewise. * string/test-strlen.c (do_random_tests): Likewise. * string/test-strpbrk.c (do_test, do_random_tests): Likewise. * string/test-strcmp.c (do_random_tests): Likewise. * string/test-strchr.c (do_test, do_random_tests): Likewise. * string/test-strcat.c (do_test, do_random_tests): Likewise. * string/test-strncpy.c (do_random_tests): Likewise. * string/test-strcpy.c (do_test, do_random_tests): Likewise. * string/test-memccpy.c (do_test): Likewise. * string/test-memmove.c (do_test, do_random_tests): Likewise. * string/test-memcpy.c (do_test, do_random_tests): Likewise. * string/test-memcmp.c (do_test, do_random_tests): Likewise. * string/test-memchr.c (do_test, do_random_tests): Likewise. * dlfcn/bug-atexit1.c (do_test): Fix up prototype in cast. * stdio-common/tst-fgets.c (do_test): Add a cast. * iconvdata/bug-iconv4.c (xiconv): Add a cast. * locale/programs/simple-hash.c (insert_entry_2): Remove useless casts. * resolv/herror.c (herror): Remove unused extern decl. * libio/obprintf.c: Include "strfile.h". * elf/order2mod2.c (init): Cast ignored value to void. * stdio-common/tstdiomisc.c: If FLT_EVAL_METHOD is 2, use long
2005-12-27 22:50:12 +00:00
char *outp = (char *) euc;
size_t inbytesleft = strlen (UCS_STR);
size_t outbytesleft = out_size;
size_t ret;
bool fail = false;
errno = 0;
ret = iconv (cd, &inp, &inbytesleft, &outp, &outbytesleft);
if (errno || ret == (size_t) -1)
{
fail = out_size == 4 || errno != E2BIG;
printf ("expected %d (E2BIG), got %d (%m)\n", E2BIG, errno);
}
else
{
printf ("%s: 0x%02x%02x\n", to_code, euc[0], euc[1]);
if (out_size == 1)
fail = true;
}
return fail;
}
static iconv_t
xiconv_open (const char *code)
{
iconv_t cd;
to_code = code;
errno = 0;
if (errno || (cd = iconv_open (to_code, "UCS-2BE")) == (iconv_t) -1)
{
puts ("Can't open converter");
exit (1);
}
return cd;
}
int
main (void)
{
iconv_t cd;
int result = 0;
cd = xiconv_open ("EUC-TW");
result |= xiconv (cd, 4) == true;
puts ("---");
result |= xiconv (cd, 1) == true;
puts ("---");
iconv_close (cd);
cd = xiconv_open ("EUC-JP");
result |= xiconv (cd, 4) == true;
puts ("---");
result |= xiconv (cd, 1) == true;
puts ("---");
iconv_close (cd);
return result;
}