lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include <iconv.h> |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | #include <string.h> |
| 6 | |
| 7 | |
| 8 | static int |
| 9 | do_test (void) |
| 10 | { |
| 11 | iconv_t cd = iconv_open ("ISO-8859-1", "UNICODE"); |
| 12 | if (cd == (iconv_t) -1) |
| 13 | { |
| 14 | printf ("iconv_open failed: %m\n"); |
| 15 | exit (EXIT_FAILURE); |
| 16 | } |
| 17 | |
| 18 | char instr[] = "a"; |
| 19 | char *inptr = instr; |
| 20 | size_t inlen = strlen (instr); |
| 21 | char buf[200]; |
| 22 | char *outptr = buf; |
| 23 | size_t outlen = sizeof (outptr); |
| 24 | |
| 25 | errno = 0; |
| 26 | size_t n = iconv (cd, &inptr, &inlen, &outptr, &outlen); |
| 27 | if (n != (size_t) -1) |
| 28 | { |
| 29 | printf ("n (= %zu) != (size_t) -1\n", n); |
| 30 | exit (EXIT_FAILURE); |
| 31 | } |
| 32 | if (errno != EINVAL) |
| 33 | { |
| 34 | printf ("errno = %m, not EINVAL\n"); |
| 35 | exit (EXIT_FAILURE); |
| 36 | } |
| 37 | |
| 38 | iconv_close (cd); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | #define TEST_FUNCTION do_test () |
| 44 | #include "../test-skeleton.c" |