summaryrefslogtreecommitdiffstats
path: root/gl/localcharset.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/localcharset.c')
-rw-r--r--gl/localcharset.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/gl/localcharset.c b/gl/localcharset.c
index fa2207fe..a225a2ea 100644
--- a/gl/localcharset.c
+++ b/gl/localcharset.c
@@ -1,6 +1,6 @@
1/* Determine a canonical name for the current locale's character encoding. 1/* Determine a canonical name for the current locale's character encoding.
2 2
3 Copyright (C) 2000-2006, 2008-2010 Free Software Foundation, Inc. 3 Copyright (C) 2000-2006, 2008-2013 Free Software Foundation, Inc.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
@@ -13,8 +13,7 @@
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, 16 with this program; if not, see <http://www.gnu.org/licenses/>. */
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 17
19/* Written by Bruno Haible <bruno@clisp.org>. */ 18/* Written by Bruno Haible <bruno@clisp.org>. */
20 19
@@ -30,11 +29,11 @@
30#include <stdlib.h> 29#include <stdlib.h>
31 30
32#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET 31#if defined __APPLE__ && defined __MACH__ && HAVE_LANGINFO_CODESET
33# define DARWIN7 /* Darwin 7 or newer, i.e. MacOS X 10.3 or newer */ 32# define DARWIN7 /* Darwin 7 or newer, i.e. Mac OS X 10.3 or newer */
34#endif 33#endif
35 34
36#if defined _WIN32 || defined __WIN32__ 35#if defined _WIN32 || defined __WIN32__
37# define WIN32_NATIVE 36# define WINDOWS_NATIVE
38#endif 37#endif
39 38
40#if defined __EMX__ 39#if defined __EMX__
@@ -44,7 +43,7 @@
44# endif 43# endif
45#endif 44#endif
46 45
47#if !defined WIN32_NATIVE 46#if !defined WINDOWS_NATIVE
48# include <unistd.h> 47# include <unistd.h>
49# if HAVE_LANGINFO_CODESET 48# if HAVE_LANGINFO_CODESET
50# include <langinfo.h> 49# include <langinfo.h>
@@ -57,7 +56,7 @@
57# define WIN32_LEAN_AND_MEAN 56# define WIN32_LEAN_AND_MEAN
58# include <windows.h> 57# include <windows.h>
59# endif 58# endif
60#elif defined WIN32_NATIVE 59#elif defined WINDOWS_NATIVE
61# define WIN32_LEAN_AND_MEAN 60# define WIN32_LEAN_AND_MEAN
62# include <windows.h> 61# include <windows.h>
63#endif 62#endif
@@ -66,6 +65,11 @@
66# include <os2.h> 65# include <os2.h>
67#endif 66#endif
68 67
68/* For MB_CUR_MAX_L */
69#if defined DARWIN7
70# include <xlocale.h>
71#endif
72
69#if ENABLE_RELOCATABLE 73#if ENABLE_RELOCATABLE
70# include "relocatable.h" 74# include "relocatable.h"
71#else 75#else
@@ -83,7 +87,7 @@
83#endif 87#endif
84 88
85#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ 89#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
86 /* Win32, Cygwin, OS/2, DOS */ 90 /* Native Windows, Cygwin, OS/2, DOS */
87# define ISSLASH(C) ((C) == '/' || (C) == '\\') 91# define ISSLASH(C) ((C) == '/' || (C) == '\\')
88#endif 92#endif
89 93
@@ -123,7 +127,7 @@ get_charset_aliases (void)
123 cp = charset_aliases; 127 cp = charset_aliases;
124 if (cp == NULL) 128 if (cp == NULL)
125 { 129 {
126#if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) 130#if !(defined DARWIN7 || defined VMS || defined WINDOWS_NATIVE || defined __CYGWIN__)
127 const char *dir; 131 const char *dir;
128 const char *base = "charset.alias"; 132 const char *base = "charset.alias";
129 char *file_name; 133 char *file_name;
@@ -228,8 +232,7 @@ get_charset_aliases (void)
228 { 232 {
229 /* Out of memory. */ 233 /* Out of memory. */
230 res_size = 0; 234 res_size = 0;
231 if (old_res_ptr != NULL) 235 free (old_res_ptr);
232 free (old_res_ptr);
233 break; 236 break;
234 } 237 }
235 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); 238 strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1);
@@ -309,7 +312,7 @@ get_charset_aliases (void)
309 "DECKOREAN" "\0" "EUC-KR" "\0"; 312 "DECKOREAN" "\0" "EUC-KR" "\0";
310# endif 313# endif
311 314
312# if defined WIN32_NATIVE || defined __CYGWIN__ 315# if defined WINDOWS_NATIVE || defined __CYGWIN__
313 /* To avoid the troubles of installing a separate file in the same 316 /* To avoid the troubles of installing a separate file in the same
314 directory as the DLL and of retrieving the DLL's directory at 317 directory as the DLL and of retrieving the DLL's directory at
315 runtime, simply inline the aliases here. */ 318 runtime, simply inline the aliases here. */
@@ -361,7 +364,7 @@ locale_charset (void)
361 const char *codeset; 364 const char *codeset;
362 const char *aliases; 365 const char *aliases;
363 366
364#if !(defined WIN32_NATIVE || defined OS2) 367#if !(defined WINDOWS_NATIVE || defined OS2)
365 368
366# if HAVE_LANGINFO_CODESET 369# if HAVE_LANGINFO_CODESET
367 370
@@ -408,10 +411,10 @@ locale_charset (void)
408 } 411 }
409 } 412 }
410 413
411 /* Woe32 has a function returning the locale's codepage as a number: 414 /* The Windows API has a function returning the locale's codepage as a
412 GetACP(). This encoding is used by Cygwin, unless the user has set 415 number: GetACP(). This encoding is used by Cygwin, unless the user
413 the environment variable CYGWIN=codepage:oem (which very few people 416 has set the environment variable CYGWIN=codepage:oem (which very few
414 do). 417 people do).
415 Output directed to console windows needs to be converted (to 418 Output directed to console windows needs to be converted (to
416 GetOEMCP() if the console is using a raster font, or to 419 GetOEMCP() if the console is using a raster font, or to
417 GetConsoleOutputCP() if it is using a TrueType font). Cygwin does 420 GetConsoleOutputCP() if it is using a TrueType font). Cygwin does
@@ -454,12 +457,12 @@ locale_charset (void)
454 457
455# endif 458# endif
456 459
457#elif defined WIN32_NATIVE 460#elif defined WINDOWS_NATIVE
458 461
459 static char buf[2 + 10 + 1]; 462 static char buf[2 + 10 + 1];
460 463
461 /* Woe32 has a function returning the locale's codepage as a number: 464 /* The Windows API has a function returning the locale's codepage as a
462 GetACP(). 465 number: GetACP().
463 When the output goes to a console window, it needs to be provided in 466 When the output goes to a console window, it needs to be provided in
464 GetOEMCP() encoding if the console is using a raster font, or in 467 GetOEMCP() encoding if the console is using a raster font, or in
465 GetConsoleOutputCP() encoding if it is using a TrueType font. 468 GetConsoleOutputCP() encoding if it is using a TrueType font.
@@ -544,5 +547,12 @@ locale_charset (void)
544 if (codeset[0] == '\0') 547 if (codeset[0] == '\0')
545 codeset = "ASCII"; 548 codeset = "ASCII";
546 549
550#ifdef DARWIN7
551 /* Mac OS X sets MB_CUR_MAX to 1 when LC_ALL=C, and "UTF-8"
552 (the default codeset) does not work when MB_CUR_MAX is 1. */
553 if (strcmp (codeset, "UTF-8") == 0 && MB_CUR_MAX_L (uselocale (NULL)) <= 1)
554 codeset = "ASCII";
555#endif
556
547 return codeset; 557 return codeset;
548} 558}