lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <string.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <errno.h> |
| 5 | #include <iconv.h> |
| 6 | #include <locale.h> |
| 7 | |
| 8 | static const char testbuf[] = { |
| 9 | 0xEF, 0xBE, 0x9F, 0xD0, 0xB4, 0xEF, 0xBE, 0x9F, 0x29, 0xEF, 0xBE, 0x8E, |
| 10 | 0xEF, 0xBE, 0x9F, 0xEF, 0xBD, 0xB6, 0xEF, 0xBD, 0xB0, 0xEF, 0xBE, 0x9D |
| 11 | }; |
| 12 | |
| 13 | static int |
| 14 | do_test (void) |
| 15 | { |
| 16 | setlocale (LC_ALL, "de_DE.UTF-8"); |
| 17 | iconv_t ic = iconv_open ("ISO-2022-JP//TRANSLIT", "UTF-8"); |
| 18 | if (ic == (iconv_t) -1) |
| 19 | { |
| 20 | puts ("iconv_open failed"); |
| 21 | return 1; |
| 22 | } |
| 23 | size_t outremain = sizeof testbuf; |
| 24 | char outbuf[outremain]; |
| 25 | char *inp = (char *) testbuf; |
| 26 | char *outp = outbuf; |
| 27 | size_t inremain = sizeof testbuf; |
| 28 | |
| 29 | int ret = iconv (ic, &inp, &inremain, &outp, &outremain); |
| 30 | |
| 31 | int result = 0; |
| 32 | if (ret == (size_t) -1) |
| 33 | { |
| 34 | if (errno == E2BIG) |
| 35 | puts ("buffer too small reported. OK"); |
| 36 | else |
| 37 | { |
| 38 | printf ("iconv failed with %d (%m)\n", errno); |
| 39 | result = 0; |
| 40 | } |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | printf ("iconv returned %d\n", ret); |
| 45 | result = 1; |
| 46 | } |
| 47 | |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | #define TEST_FUNCTION do_test () |
| 52 | #include "../test-skeleton.c" |