31
/* Depending on which standard the iconv() was implemented with,
32
iconv() may or may not use const char ** for the inbuf param.
33
If we get this wrong, it's just a warning, so no big deal.
35
#if defined(_XGP6) || \
36
defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
37
#define ICONV_INBUF_NONCONST
33
42
size_t SDL_iconv(SDL_iconv_t cd,
34
char **inbuf, size_t *inbytesleft,
43
const char **inbuf, size_t *inbytesleft,
35
44
char **outbuf, size_t *outbytesleft)
37
size_t retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
47
#ifdef ICONV_INBUF_NONCONST
48
retCode = iconv(cd, (char **)inbuf, inbytesleft, outbuf, outbytesleft);
50
retCode = iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);
38
52
if ( retCode == (size_t)-1 ) {
96
110
{ "ASCII", ENCODING_ASCII },
97
111
{ "US-ASCII", ENCODING_ASCII },
98
{ "LATIN1", ENCODING_LATIN1 },
112
{ "8859-1", ENCODING_LATIN1 },
99
113
{ "ISO-8859-1", ENCODING_LATIN1 },
100
114
{ "UTF8", ENCODING_UTF8 },
101
115
{ "UTF-8", ENCODING_UTF8 },
117
131
{ "UCS-4", ENCODING_UCS4 },
134
static const char *getlocale(char *buffer, size_t bufsize)
139
lang = SDL_getenv("LC_ALL");
141
lang = SDL_getenv("LC_CTYPE");
144
lang = SDL_getenv("LC_MESSAGES");
147
lang = SDL_getenv("LANG");
149
if ( !lang || !*lang || SDL_strcmp(lang, "C") == 0 ) {
153
/* We need to trim down strings like "en_US.UTF-8@blah" to "UTF-8" */
154
ptr = SDL_strchr(lang, '.');
159
SDL_strlcpy(buffer, lang, bufsize);
160
ptr = SDL_strchr(buffer, '@');
162
*ptr = '\0'; /* chop end of string. */
120
168
SDL_iconv_t SDL_iconv_open(const char *tocode, const char *fromcode)
122
170
int src_fmt = ENCODING_UNKNOWN;
123
171
int dst_fmt = ENCODING_UNKNOWN;
173
char fromcode_buffer[64];
174
char tocode_buffer[64];
176
if ( !fromcode || !*fromcode ) {
177
fromcode = getlocale(fromcode_buffer, sizeof(fromcode_buffer));
179
if ( !tocode || !*tocode ) {
180
tocode = getlocale(tocode_buffer, sizeof(tocode_buffer));
126
182
for ( i = 0; i < SDL_arraysize(encodings); ++i ) {
127
183
if ( SDL_strcasecmp(fromcode, encodings[i].name) == 0 ) {
128
184
src_fmt = encodings[i].format;
151
207
size_t SDL_iconv(SDL_iconv_t cd,
152
char **inbuf, size_t *inbytesleft,
208
const char **inbuf, size_t *inbytesleft,
153
209
char **outbuf, size_t *outbytesleft)
155
211
/* For simplicity, we'll convert everything to and from UCS-4 */
157
214
size_t srclen, dstlen;
756
813
#endif /* !HAVE_ICONV */
758
char *SDL_iconv_string(const char *tocode, const char *fromcode, char *inbuf, size_t inbytesleft)
815
char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
767
824
cd = SDL_iconv_open(tocode, fromcode);
768
825
if ( cd == (SDL_iconv_t)-1 ) {
826
/* See if we can recover here (fixes iconv on Solaris 11) */
827
if ( !tocode || !*tocode ) {
830
if ( !fromcode || !*fromcode ) {
833
cd = SDL_iconv_open(tocode, fromcode);
835
if ( cd == (SDL_iconv_t)-1 ) {