/* Determine name of the currently selected locale.
- Copyright (C) 1995-2010 Free Software Foundation, Inc.
+ Copyright (C) 1995-2012 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU Library General Public License as published
- by the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- USA. */
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Ulrich Drepper <drepper@gnu.org>, 1995. */
-/* Win32 code written by Tor Lillqvist <tml@iki.fi>. */
-/* MacOS X code written by Bruno Haible <bruno@clisp.org>. */
+/* Native Windows code written by Tor Lillqvist <tml@iki.fi>. */
+/* Mac OS X code written by Bruno Haible <bruno@clisp.org>. */
#include <config.h>
#include <string.h>
#if HAVE_USELOCALE
-/* MacOS X 10.5 defines the locale_t type in <xlocale.h>. */
+/* Mac OS X 10.5 defines the locale_t type in <xlocale.h>. */
# if defined __APPLE__ && defined __MACH__
# include <xlocale.h>
# endif
#endif
#if defined _WIN32 || defined __WIN32__
-# define WIN32_NATIVE
+# define WINDOWS_NATIVE
#endif
-#if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
+#if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
/* List of language codes, sorted by value:
#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
-/* MacOS X 10.2 or newer */
+/* Mac OS X 10.2 or newer */
-/* Canonicalize a MacOS X locale name to a Unix locale name.
+/* Canonicalize a Mac OS X locale name to a Unix locale name.
NAME is a sufficiently large buffer.
- On input, it contains the MacOS X locale name.
+ On input, it contains the Mac OS X locale name.
On output, it contains the Unix locale name. */
# if !defined IN_LIBINTL
static
http://lists.apple.com/archives/carbon-dev/2005/Mar/msg00293.html */
/* Convert legacy (NeXTstep inherited) English names to Unix (ISO 639 and
- ISO 3166) names. Prior to MacOS X 10.3, there is no API for doing this.
+ ISO 3166) names. Prior to Mac OS X 10.3, there is no API for doing this.
Therefore we do it ourselves, using a table based on the results of the
- MacOS X 10.3.8 function
+ Mac OS X 10.3.8 function
CFLocaleCreateCanonicalLocaleIdentifierFromString(). */
typedef struct { const char legacy[21+1]; const char unixy[5+1]; }
legacy_entry;
typedef struct { const char langtag[7+1]; const char unixy[12+1]; }
langtag_entry;
static const langtag_entry langtag_table[] = {
- /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn".
+ /* Mac OS X has "az-Arab", "az-Cyrl", "az-Latn".
The default script for az on Unix is Latin. */
{ "az-Latn", "az" },
- /* MacOS X has "ga-dots". Does not yet exist on Unix. */
+ /* Mac OS X has "ga-dots". Does not yet exist on Unix. */
{ "ga-dots", "ga" },
- /* MacOS X has "kk-Cyrl". Does not yet exist on Unix. */
- /* MacOS X has "mn-Cyrl", "mn-Mong".
+ /* Mac OS X has "kk-Cyrl". Does not yet exist on Unix. */
+ /* Mac OS X has "mn-Cyrl", "mn-Mong".
The default script for mn on Unix is Cyrillic. */
{ "mn-Cyrl", "mn" },
- /* MacOS X has "ms-Arab", "ms-Latn".
+ /* Mac OS X has "ms-Arab", "ms-Latn".
The default script for ms on Unix is Latin. */
{ "ms-Latn", "ms" },
- /* MacOS X has "tg-Cyrl".
+ /* Mac OS X has "tg-Cyrl".
The default script for tg on Unix is Cyrillic. */
{ "tg-Cyrl", "tg" },
- /* MacOS X has "tk-Cyrl". Does not yet exist on Unix. */
- /* MacOS X has "tt-Cyrl".
+ /* Mac OS X has "tk-Cyrl". Does not yet exist on Unix. */
+ /* Mac OS X has "tt-Cyrl".
The default script for tt on Unix is Cyrillic. */
{ "tt-Cyrl", "tt" },
- /* MacOS X has "zh-Hans", "zh-Hant".
+ /* Mac OS X has "zh-Hans", "zh-Hant".
Country codes are used to distinguish these on Unix. */
{ "zh-Hans", "zh_CN" },
{ "zh-Hant", "zh_TW" }
#endif
-#if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
+#if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
-/* Canonicalize a Win32 native locale name to a Unix locale name.
+/* Canonicalize a Windows native locale name to a Unix locale name.
NAME is a sufficiently large buffer.
- On input, it contains the Win32 locale name.
+ On input, it contains the Windows locale name.
On output, it contains the Unix locale name. */
# if !defined IN_LIBINTL
static
}
/* Internet Explorer has an LCID to RFC3066 name mapping stored in
HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that
- since IE's i18n subsystem is known to be inconsistent with the Win32 base
- (e.g. they have different character conversion facilities that produce
- different results). */
+ since IE's i18n subsystem is known to be inconsistent with the native
+ Windows base (e.g. they have different character conversion facilities
+ that produce different results). */
/* Use our own table. */
{
int primary, sub;
#endif
-#if HAVE_USELOCALE /* glibc or MacOS X */
+#if HAVE_USELOCALE /* glibc or Mac OS X */
/* Simple hash set of strings. We don't want to drag in lots of hash table
code here. */
nl_langinfo (_NL_LOCALE_NAME (category)). */
name = thread_locale->__names[category];
return name;
-# endif
-# if defined __APPLE__ && defined __MACH__ /* MacOS X */
- /* The locale name is found deep in an undocumented data structure.
- Since it's stored in a buffer of size 32 and newlocale() rejects
- locale names of length > 31, we can assume that it is NUL terminated
- in this buffer. But we need to make a copy of the locale name, of
- indefinite extent. */
- struct _xlocale_part1_v0 /* used in MacOS X 10.5 */
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- __darwin_mbstate_t __mbs[10];
- int64_t __magic;
- };
- struct _xlocale_part1_v1 /* used in MacOS X >= 10.6.0 */
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- __darwin_mbstate_t __mbs[10];
- /*pthread_lock_t*/ int __lock;
- int64_t __magic;
- };
- struct _xlocale_part2
- {
- int64_t __magic;
- unsigned char __collate_load_error;
- unsigned char __collate_substitute_nontrivial;
- unsigned char _messages_using_locale;
- unsigned char _monetary_using_locale;
- unsigned char _numeric_using_locale;
- unsigned char _time_using_locale;
- unsigned char __mlocale_changed;
- unsigned char __nlocale_changed;
- unsigned char __numeric_fp_cvt;
- struct __xlocale_st_collate *__lc_collate;
- struct __xlocale_st_runelocale *__lc_ctype;
- struct __xlocale_st_messages *__lc_messages;
- struct __xlocale_st_monetary *__lc_monetary;
- struct __xlocale_st_numeric *__lc_numeric;
- struct _xlocale *__lc_numeric_loc;
- struct __xlocale_st_time *__lc_time;
- /* more */
- };
- struct __xlocale_st_collate
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char __encoding[32];
- /* more */
- };
- struct __xlocale_st_runelocale
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char __ctype_encoding[32];
- /* more */
- };
- struct __xlocale_st_messages
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char *_messages_locale_buf;
- /* more */
- };
- struct __xlocale_st_monetary
- {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char *_monetary_locale_buf;
- /* more */
- };
- struct __xlocale_st_numeric {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char *_numeric_locale_buf;
- /* more */
- };
- struct __xlocale_st_time {
- int32_t __refcount;
- void (*__free_extra)(void *);
- char *_time_locale_buf;
- /* more */
- };
- struct _xlocale_part2 *tlp;
- if (((struct _xlocale_part1_v0 *) thread_locale)->__magic
- == 0x786C6F63616C6530LL)
- /* MacOS X 10.5 */
- tlp =
- (struct _xlocale_part2 *)
- &((struct _xlocale_part1_v0 *) thread_locale)->__magic;
- else if (((struct _xlocale_part1_v1 *) thread_locale)->__magic
- == 0x786C6F63616C6530LL)
- /* MacOS X >= 10.6.0 */
- tlp =
- (struct _xlocale_part2 *)
- &((struct _xlocale_part1_v1 *) thread_locale)->__magic;
- else
- /* Unsupported version of MacOS X: The internals of 'struct _xlocale'
- have changed again. */
- return "";
+# elif defined __FreeBSD__ || (defined __APPLE__ && defined __MACH__)
+ /* FreeBSD, Mac OS X */
+ int mask;
+
switch (category)
{
case LC_CTYPE:
- return tlp->__lc_ctype->__ctype_encoding;
+ mask = LC_CTYPE_MASK;
+ break;
case LC_NUMERIC:
- return tlp->_numeric_using_locale
- ? tlp->__lc_numeric->_numeric_locale_buf
- : "C";
+ mask = LC_NUMERIC_MASK;
+ break;
case LC_TIME:
- return tlp->_time_using_locale
- ? tlp->__lc_time->_time_locale_buf
- : "C";
+ mask = LC_TIME_MASK;
+ break;
case LC_COLLATE:
- return !tlp->__collate_load_error
- ? tlp->__lc_collate->__encoding
- : "C";
+ mask = LC_COLLATE_MASK;
+ break;
case LC_MONETARY:
- return tlp->_monetary_using_locale
- ? tlp->__lc_monetary->_monetary_locale_buf
- : "C";
+ mask = LC_MONETARY_MASK;
+ break;
case LC_MESSAGES:
- return tlp->_messages_using_locale
- ? tlp->__lc_messages->_messages_locale_buf
- : "C";
+ mask = LC_MESSAGES_MASK;
+ break;
default: /* We shouldn't get here. */
return "";
}
+ return querylocale (mask, thread_locale);
# endif
}
}
/* On other systems we ignore what setlocale reports and instead look at the
environment variables directly. This is necessary
1. on systems which have a facility for customizing the default locale
- (MacOS X, native Windows, Cygwin) and where the system's setlocale()
- function ignores this default locale (MacOS X, Cygwin), in two cases:
+ (Mac OS X, native Windows, Cygwin) and where the system's setlocale()
+ function ignores this default locale (Mac OS X, Cygwin), in two cases:
a. when the user missed to use the setlocale() override from libintl
(for example by not including <libintl.h>),
b. when setlocale supports only the "C" locale, such as on Cygwin
if (retval != NULL && retval[0] != '\0')
{
#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
- /* MacOS X 10.2 or newer.
+ /* Mac OS X 10.2 or newer.
Ignore invalid LANG value set by the Terminal application. */
if (strcmp (retval, "UTF-8") != 0)
#endif
locale, customizing it for each location. POSIX:2001 does not require
such a facility.
- The systems with such a facility are MacOS X and Windows: They provide a
+ The systems with such a facility are Mac OS X and Windows: They provide a
GUI that allows the user to choose a locale.
- - On MacOS X, by default, none of LC_* or LANG are set. Starting with
- MacOS X 10.4 or 10.5, LANG is set for processes launched by the
+ - On Mac OS X, by default, none of LC_* or LANG are set. Starting with
+ Mac OS X 10.4 or 10.5, LANG is set for processes launched by the
'Terminal' application (but sometimes to an incorrect value "UTF-8").
When no environment variable is set, setlocale (LC_ALL, "") uses the
"C" locale.
"C.UTF-8" locale, which operates in the same way as the "C" locale.
*/
-#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WIN32_NATIVE || defined __CYGWIN__)
+#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WINDOWS_NATIVE || defined __CYGWIN__)
/* The system does not have a way of setting the locale, other than the
POSIX specified environment variables. We use C as default locale. */
codeset. */
# if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE
- /* MacOS X 10.2 or newer */
+ /* Mac OS X 10.2 or newer */
{
/* Cache the locale name, since CoreFoundation calls are expensive. */
static const char *cached_localename;
if (cached_localename == NULL)
{
char namebuf[256];
-# if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */
+# if HAVE_CFLOCALECOPYCURRENT /* Mac OS X 10.3 or newer */
CFLocaleRef locale = CFLocaleCopyCurrent ();
CFStringRef name = CFLocaleGetIdentifier (locale);
cached_localename = strdup (namebuf);
}
CFRelease (locale);
-# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */
+# elif HAVE_CFPREFERENCESCOPYAPPVALUE /* Mac OS X 10.2 or newer */
CFTypeRef value =
CFPreferencesCopyAppValue (CFSTR ("AppleLocale"),
kCFPreferencesCurrentApplication);
# endif
-# if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */
+# if defined WINDOWS_NATIVE || defined __CYGWIN__ /* Native Windows or Cygwin */
{
LCID lcid;
- /* Use native Win32 API locale ID. */
+ /* Use native Windows API locale ID. */
lcid = GetThreadLocale ();
return gl_locale_name_from_win32_LCID (lcid);