Lines 42-47
Link Here
|
42 |
static iconv_t decode_conv = (iconv_t) -1; |
42 |
static iconv_t decode_conv = (iconv_t) -1; |
43 |
static iconv_t encode_conv = (iconv_t) -1; |
43 |
static iconv_t encode_conv = (iconv_t) -1; |
44 |
|
44 |
|
|
|
45 |
static const char *local_charset = NULL; |
46 |
static const char *encoding = "UTF-8"; |
47 |
|
45 |
static int utf8_convert(iconv_t conv, char *inbuf, size_t *inbuflen, |
48 |
static int utf8_convert(iconv_t conv, char *inbuf, size_t *inbuflen, |
46 |
char *outbuf, size_t *outbuflen) { |
49 |
char *outbuf, size_t *outbuflen) { |
47 |
# ifdef HAVE_ICONV |
50 |
# ifdef HAVE_ICONV |
Lines 78-87
Link Here
|
78 |
if (res < 0) |
81 |
if (res < 0) |
79 |
return -1; |
82 |
return -1; |
80 |
|
83 |
|
|
|
84 |
encode_conv = (iconv_t) -1; |
85 |
|
81 |
res = iconv_close(decode_conv); |
86 |
res = iconv_close(decode_conv); |
82 |
if (res < 0) |
87 |
if (res < 0) |
83 |
return -1; |
88 |
return -1; |
84 |
|
89 |
|
|
|
90 |
decode_conv = (iconv_t) -1; |
91 |
|
85 |
return 0; |
92 |
return 0; |
86 |
# else |
93 |
# else |
87 |
errno = ENOSYS; |
94 |
errno = ENOSYS; |
Lines 90-125
Link Here
|
90 |
} |
97 |
} |
91 |
|
98 |
|
92 |
int utf8_init(void) { |
99 |
int utf8_init(void) { |
93 |
const char *local_charset; |
|
|
94 |
|
100 |
|
|
|
101 |
if (local_charset == NULL) { |
95 |
#ifdef HAVE_NL_LANGINFO |
102 |
#ifdef HAVE_NL_LANGINFO |
96 |
/* Look up the current charset. If there's a problem, default to |
103 |
/* Look up the current charset. If there's a problem, default to |
97 |
* UCS-2. |
104 |
* UCS-2. |
98 |
*/ |
105 |
*/ |
99 |
local_charset = nl_langinfo(CODESET); |
106 |
local_charset = nl_langinfo(CODESET); |
100 |
if (!local_charset) { |
107 |
if (!local_charset) { |
|
|
108 |
local_charset = "C"; |
109 |
pr_trace_msg("utf8", 1, |
110 |
"unable to determine locale, defaulting to 'C' for UTF8 conversion"); |
111 |
|
112 |
} else { |
113 |
pr_trace_msg("utf8", 1, "converting UTF8 to local character set '%s'", |
114 |
local_charset); |
115 |
} |
116 |
#else |
101 |
local_charset = "C"; |
117 |
local_charset = "C"; |
102 |
pr_trace_msg("utf8", 1, |
118 |
pr_trace_msg("utf8", 1, |
103 |
"unable to determine locale, defaulting to 'C' for UTF8 conversion"); |
119 |
"nl_langinfo(3) not supported, defaulting to using 'C' for UTF8 " |
104 |
|
120 |
"conversion"); |
105 |
} else { |
|
|
106 |
pr_trace_msg("utf8", 1, "converting UTF8 to local character set '%s'", |
107 |
local_charset); |
108 |
} |
109 |
#else |
110 |
local_charset = "C"; |
111 |
pr_trace_msg("utf8", 1, |
112 |
"nl_langinfo(3) not supported, defaulting to using 'C' for UTF8 " |
113 |
"conversion"); |
114 |
#endif /* HAVE_NL_LANGINFO */ |
121 |
#endif /* HAVE_NL_LANGINFO */ |
|
|
122 |
} |
115 |
|
123 |
|
116 |
# ifdef HAVE_ICONV |
124 |
# ifdef HAVE_ICONV |
117 |
/* Get the iconv handles. */ |
125 |
/* Get the iconv handles. */ |
118 |
encode_conv = iconv_open(local_charset, "UTF-8"); |
126 |
encode_conv = iconv_open(encoding, local_charset); |
119 |
if (encode_conv == (iconv_t) -1) |
127 |
if (encode_conv == (iconv_t) -1) |
120 |
return -1; |
128 |
return -1; |
121 |
|
129 |
|
122 |
decode_conv = iconv_open("UTF-8", local_charset); |
130 |
decode_conv = iconv_open(local_charset, encoding); |
123 |
if (decode_conv == (iconv_t) -1) |
131 |
if (decode_conv == (iconv_t) -1) |
124 |
return -1; |
132 |
return -1; |
125 |
|
133 |
|
Lines 200-203
Link Here
|
200 |
#endif /* !HAVE_ICONV_H */ |
208 |
#endif /* !HAVE_ICONV_H */ |
201 |
} |
209 |
} |
202 |
|
210 |
|
|
|
211 |
const char *pr_utf8_get_charset(void) { |
212 |
#ifdef HAVE_ICONV_H |
213 |
return local_charset; |
214 |
|
215 |
#else |
216 |
errno = ENOSYS; |
217 |
return NULL; |
218 |
#endif /* !HAVE_ICONV_H */ |
219 |
} |
220 |
|
221 |
const char *pr_utf8_get_encoding(void) { |
222 |
#ifdef HAVE_ICONV_H |
223 |
return encoding; |
224 |
|
225 |
#else |
226 |
errno = ENOSYS; |
227 |
return NULL; |
228 |
#endif /* !HAVE_ICONV_H */ |
229 |
} |
230 |
|
203 |
#endif /* PR_USE_NLS */ |
231 |
#endif /* PR_USE_NLS */ |