This source file includes following definitions.
- rpl_iconv_open
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20 #include <iconv.h>
21
22 #include <errno.h>
23 #include <string.h>
24 #include "c-ctype.h"
25 #include "c-strcase.h"
26
27 #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
28
29
30 #define mapping_lookup rpl_iconv_open_mapping_lookup
31
32
33
34 #define ICONV_FLAVOR_AIX "iconv_open-aix.h"
35 #define ICONV_FLAVOR_HPUX "iconv_open-hpux.h"
36 #define ICONV_FLAVOR_IRIX "iconv_open-irix.h"
37 #define ICONV_FLAVOR_OSF "iconv_open-osf.h"
38 #define ICONV_FLAVOR_SOLARIS "iconv_open-solaris.h"
39 #define ICONV_FLAVOR_ZOS "iconv_open-zos.h"
40
41 #ifdef ICONV_FLAVOR
42 # include ICONV_FLAVOR
43 #endif
44
45 iconv_t
46 rpl_iconv_open (const char *tocode, const char *fromcode)
47 #undef iconv_open
48 {
49 char fromcode_upper[32];
50 char tocode_upper[32];
51 char *fromcode_upper_end;
52 char *tocode_upper_end;
53
54 #if REPLACE_ICONV_UTF
55
56
57
58
59
60
61
62
63
64 if (c_toupper (fromcode[0]) == 'U'
65 && c_toupper (fromcode[1]) == 'T'
66 && c_toupper (fromcode[2]) == 'F'
67 && fromcode[3] == '-')
68 {
69 if (c_toupper (tocode[0]) == 'U'
70 && c_toupper (tocode[1]) == 'T'
71 && c_toupper (tocode[2]) == 'F'
72 && tocode[3] == '-')
73 {
74 if (strcmp (fromcode + 4, "8") == 0)
75 {
76 if (c_strcasecmp (tocode + 4, "16BE") == 0)
77 return _ICONV_UTF8_UTF16BE;
78 if (c_strcasecmp (tocode + 4, "16LE") == 0)
79 return _ICONV_UTF8_UTF16LE;
80 if (c_strcasecmp (tocode + 4, "32BE") == 0)
81 return _ICONV_UTF8_UTF32BE;
82 if (c_strcasecmp (tocode + 4, "32LE") == 0)
83 return _ICONV_UTF8_UTF32LE;
84 }
85 else if (strcmp (tocode + 4, "8") == 0)
86 {
87 if (c_strcasecmp (fromcode + 4, "16BE") == 0)
88 return _ICONV_UTF16BE_UTF8;
89 if (c_strcasecmp (fromcode + 4, "16LE") == 0)
90 return _ICONV_UTF16LE_UTF8;
91 if (c_strcasecmp (fromcode + 4, "32BE") == 0)
92 return _ICONV_UTF32BE_UTF8;
93 if (c_strcasecmp (fromcode + 4, "32LE") == 0)
94 return _ICONV_UTF32LE_UTF8;
95 }
96 }
97 }
98 #endif
99
100
101
102
103
104
105
106
107
108
109
110
111 {
112 iconv_t cd = iconv_open (tocode, fromcode);
113 if (cd != (iconv_t)(-1))
114 return cd;
115 }
116
117
118
119
120
121 {
122 const char *p = fromcode;
123 char *q = fromcode_upper;
124 while ((*q = c_toupper (*p)) != '\0')
125 {
126 p++;
127 q++;
128 if (q == &fromcode_upper[SIZEOF (fromcode_upper)])
129 {
130 errno = EINVAL;
131 return (iconv_t)(-1);
132 }
133 }
134 fromcode_upper_end = q;
135 }
136
137 {
138 const char *p = tocode;
139 char *q = tocode_upper;
140 while ((*q = c_toupper (*p)) != '\0')
141 {
142 p++;
143 q++;
144 if (q == &tocode_upper[SIZEOF (tocode_upper)])
145 {
146 errno = EINVAL;
147 return (iconv_t)(-1);
148 }
149 }
150 tocode_upper_end = q;
151 }
152
153 #ifdef ICONV_FLAVOR
154
155 {
156 const struct mapping *m =
157 mapping_lookup (fromcode_upper, fromcode_upper_end - fromcode_upper);
158
159 fromcode = (m != NULL ? m->vendor_name : fromcode_upper);
160 }
161 {
162 const struct mapping *m =
163 mapping_lookup (tocode_upper, tocode_upper_end - tocode_upper);
164
165 tocode = (m != NULL ? m->vendor_name : tocode_upper);
166 }
167 #else
168 fromcode = fromcode_upper;
169 tocode = tocode_upper;
170 #endif
171
172 return iconv_open (tocode, fromcode);
173 }