1
1
/* Determine a canonical name for the current locale's character encoding.
3
Copyright (C) 2000-2006 Free Software Foundation, Inc.
3
Copyright (C) 2000-2004 Free Software Foundation, Inc.
5
5
This program is free software; you can redistribute it and/or modify it
6
6
under the terms of the GNU Library General Public License as published
41
#if !defined WIN32_NATIVE
42
54
# if HAVE_LANGINFO_CODESET
43
55
# include <langinfo.h>
45
# if 0 /* see comment below */
46
58
# include <locale.h>
50
# define WIN32_LEAN_AND_MEAN
53
#elif defined WIN32_NATIVE
54
62
# define WIN32_LEAN_AND_MEAN
55
63
# include <windows.h>
65
73
# define relocate(pathname) (pathname)
70
# include "configmake.h"
73
76
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
74
77
/* Win32, Cygwin, OS/2, DOS */
75
78
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
105
108
/* Return a pointer to the contents of the charset.alias file. */
106
109
static const char *
107
get_charset_aliases (void)
110
get_charset_aliases ()
111
114
cp = charset_aliases;
114
#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
117
#if !(defined VMS || defined WIN32)
117
120
const char *base = "charset.alias";
237
240
"DECKOREAN" "\0" "EUC-KR" "\0";
240
# if defined WIN32_NATIVE || defined __CYGWIN__
241
244
/* To avoid the troubles of installing a separate file in the same
242
245
directory as the DLL and of retrieving the DLL's directory at
243
246
runtime, simply inline the aliases here. */
246
249
"CP1361" "\0" "JOHAB" "\0"
247
250
"CP20127" "\0" "ASCII" "\0"
248
251
"CP20866" "\0" "KOI8-R" "\0"
249
"CP20936" "\0" "GB2312" "\0"
250
252
"CP21866" "\0" "KOI8-RU" "\0"
251
253
"CP28591" "\0" "ISO-8859-1" "\0"
252
254
"CP28592" "\0" "ISO-8859-2" "\0"
257
259
"CP28597" "\0" "ISO-8859-7" "\0"
258
260
"CP28598" "\0" "ISO-8859-8" "\0"
259
261
"CP28599" "\0" "ISO-8859-9" "\0"
260
"CP28605" "\0" "ISO-8859-15" "\0"
261
"CP38598" "\0" "ISO-8859-8" "\0"
262
"CP51932" "\0" "EUC-JP" "\0"
263
"CP51936" "\0" "GB2312" "\0"
264
"CP51949" "\0" "EUC-KR" "\0"
265
"CP51950" "\0" "EUC-TW" "\0"
266
"CP54936" "\0" "GB18030" "\0"
267
"CP65001" "\0" "UTF-8" "\0";
262
"CP28605" "\0" "ISO-8859-15" "\0";
287
locale_charset (void)
289
284
const char *codeset;
290
285
const char *aliases;
292
#if !(defined WIN32_NATIVE || defined OS2)
287
#if !(defined WIN32 || defined OS2)
294
289
# if HAVE_LANGINFO_CODESET
296
291
/* Most systems support nl_langinfo (CODESET) nowadays. */
297
292
codeset = nl_langinfo (CODESET);
300
/* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always
301
returns "US-ASCII". As long as this is not fixed, return the suffix
302
of the locale name from the environment variables (if present) or
303
the codepage as a number. */
304
if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
307
static char buf[2 + 10 + 1];
309
locale = getenv ("LC_ALL");
310
if (locale == NULL || locale[0] == '\0')
312
locale = getenv ("LC_CTYPE");
313
if (locale == NULL || locale[0] == '\0')
314
locale = getenv ("LANG");
316
if (locale != NULL && locale[0] != '\0')
318
/* If the locale name contains an encoding after the dot, return
320
const char *dot = strchr (locale, '.');
324
const char *modifier;
327
/* Look for the possible @... trailer and remove it, if any. */
328
modifier = strchr (dot, '@');
329
if (modifier == NULL)
331
if (modifier - dot < sizeof (buf))
333
memcpy (buf, dot, modifier - dot);
334
buf [modifier - dot] = '\0';
340
/* Woe32 has a function returning the locale's codepage as a number. */
341
sprintf (buf, "CP%u", GetACP ());
348
296
/* On old systems which lack it, use setlocale or getenv. */
352
300
(like SunOS 4 or DJGPP) have only the C locale. Therefore we don't
353
301
use setlocale here; it would return "C" when it doesn't support the
354
302
locale name the user has set. */
303
# if HAVE_SETLOCALE && 0
356
304
locale = setlocale (LC_CTYPE, NULL);
358
306
if (locale == NULL || locale[0] == '\0')