1 | |
2 | #include <stdio.h> |
3 | #include <stdlib.h> |
4 | #include <iconv.h> |
5 | |
6 | int |
7 | main (void) |
8 | { |
9 | const char *dummy_codesets[] = |
10 | { |
11 | "ISO_8859-1" , "ISO_8859-2" , "ISO_8859-3" , "ISO_8859-4" , |
12 | "ISO_8859-5" , "ISO_8859-6" , "ISO_8859-7" , "ISO_8859-8" |
13 | }; |
14 | iconv_t dummy_cd[8], cd_a; |
15 | int i; |
16 | char buffer[1024], *to = buffer; |
17 | char *from = (char *) "foobar" ; |
18 | size_t to_left = 1024, from_left = 6; |
19 | |
20 | /* load dummy modules */ |
21 | for (i = 0; i < 8; i++) |
22 | if ((dummy_cd[i] = iconv_open (tocode: dummy_codesets[i], fromcode: "UTF8" )) == (iconv_t) -1) |
23 | exit (status: 1); |
24 | |
25 | /* load a module... */ |
26 | if ((cd_a = iconv_open (tocode: "EUC-JP" , fromcode: "UTF8" )) == (iconv_t) -1) |
27 | exit (status: 1); |
28 | /* and close it once. we'll reload this later */ |
29 | iconv_close (cd: cd_a); |
30 | |
31 | /* unload dummy modules */ |
32 | for (i = 0; i < 8; i++) |
33 | iconv_close (cd: dummy_cd[i]); |
34 | |
35 | /* load the module again */ |
36 | if ((cd_a = iconv_open (tocode: "EUC-JP" , fromcode: "UTF8" )) == (iconv_t) -1) |
37 | exit (status: 1); |
38 | |
39 | puts (s: "This used to crash" ); |
40 | printf (format: "%zd\n" , iconv (cd: cd_a, inbuf: &from, inbytesleft: &from_left, outbuf: &to, outbytesleft: &to_left)); |
41 | iconv_close (cd: cd_a); |
42 | |
43 | puts (s: "works now" ); |
44 | |
45 | return 0; |
46 | } |
47 | |