summaryrefslogtreecommitdiff
path: root/lib/localename.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-07-08 23:15:22 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-07-08 23:15:22 +0200
commit853c9cf3718db7c9f6d723e45031016231e1cbd1 (patch)
treee6a5cafe819de3d14665da32bfd87259b089ec02 /lib/localename.c
parent7b350538dddb27a4513158cb6b6405b85f175ad1 (diff)
parent10bd216b0099d2ae8cb22c664fb725165096f95c (diff)
Merge branch 'release/debian/0.9.10-1'debian/0.9.10-1
Diffstat (limited to 'lib/localename.c')
-rw-r--r--lib/localename.c77
1 files changed, 51 insertions, 26 deletions
diff --git a/lib/localename.c b/lib/localename.c
index 59732fa9..7432978d 100644
--- a/lib/localename.c
+++ b/lib/localename.c
@@ -1,5 +1,5 @@
/* Determine name of the currently selected locale.
- Copyright (C) 1995-2017 Free Software Foundation, Inc.
+ Copyright (C) 1995-2018 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or
modify it under the terms of either:
@@ -49,7 +49,7 @@
# if defined __APPLE__ && defined __MACH__
# include <xlocale.h>
# endif
-# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || defined __CYGWIN__
+# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || (defined __linux__ && HAVE_LANGINFO_H) || defined __CYGWIN__
# include <langinfo.h>
# endif
# if !defined IN_LIBINTL
@@ -70,7 +70,7 @@ extern char * getlocalename_l(int, locale_t);
# endif
#endif
-#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+#if defined _WIN32 && !defined __CYGWIN__
# define WINDOWS_NATIVE
# if !defined IN_LIBINTL
# include "glthread/lock.h"
@@ -1340,7 +1340,7 @@ gl_locale_name_canonicalize (char *name)
};
/* Convert script names (ISO 15924) to Unix conventions.
- See http://www.unicode.org/iso15924/iso15924-codes.html */
+ See https://www.unicode.org/iso15924/iso15924-codes.html */
typedef struct { const char script[4+1]; const char unixy[9+1]; }
script_entry;
static const script_entry script_table[] = {
@@ -1501,7 +1501,7 @@ gl_locale_name_from_win32_LANGID (LANGID langid)
sub = SUBLANGID (langid);
/* Dispatch on language.
- See also http://www.unicode.org/unicode/onlinedat/languages.html .
+ See also https://www.unicode.org/unicode/onlinedat/languages.html .
For details about languages, see https://www.ethnologue.com/ . */
switch (primary)
{
@@ -2601,7 +2601,7 @@ get_lcid (const char *locale_name)
#endif
-#if HAVE_USELOCALE /* glibc, Solaris >= 12 or Mac OS X */
+#if HAVE_USELOCALE /* glibc, Mac OS X, Solaris 11 OpenIndiana, or Solaris 12 */
/* Simple hash set of strings. We don't want to drag in lots of hash table
code here. */
@@ -2712,6 +2712,9 @@ gl_locale_name_thread_unsafe (int category, const char *categoryname)
nl_langinfo (_NL_LOCALE_NAME (category)). */
name = thread_locale->__names[category];
return name;
+# elif defined __linux__ && HAVE_LANGINFO_H && defined NL_LOCALE_NAME
+ /* musl libc */
+ return nl_langinfo_l (NL_LOCALE_NAME (category), thread_locale);
# elif (defined __FreeBSD__ || defined __DragonFly__) || (defined __APPLE__ && defined __MACH__)
/* FreeBSD, Mac OS X */
int mask;
@@ -2740,9 +2743,27 @@ gl_locale_name_thread_unsafe (int category, const char *categoryname)
return "";
}
return querylocale (mask, thread_locale);
-# elif defined __sun && HAVE_GETLOCALENAME_L
+# elif defined __sun
+# if HAVE_GETLOCALENAME_L
/* Solaris >= 12. */
return getlocalename_l (category, thread_locale);
+# else
+ /* Solaris 11 OpenIndiana.
+ For the internal structure of locale objects, see
+ https://github.com/OpenIndiana/illumos-gate/blob/master/usr/src/lib/libc/port/locale/localeimpl.h */
+ switch (category)
+ {
+ case LC_CTYPE:
+ case LC_NUMERIC:
+ case LC_TIME:
+ case LC_COLLATE:
+ case LC_MONETARY:
+ case LC_MESSAGES:
+ return ((const char * const *) thread_locale)[category];
+ default: /* We shouldn't get here. */
+ return "";
+ }
+# endif
# elif defined __CYGWIN__
/* Cygwin < 2.6 lacks uselocale and thread-local locales altogether.
Cygwin <= 2.6.1 lacks NL_LOCALE_NAME, requiring peeking inside
@@ -2774,7 +2795,27 @@ gl_locale_name_thread (int category, const char *categoryname)
const char *name = gl_locale_name_thread_unsafe (category, categoryname);
if (name != NULL)
return struniq (name);
-#elif defined WINDOWS_NATIVE
+#endif
+ /* On WINDOWS_NATIVE, don't use GetThreadLocale() here, because when
+ SetThreadLocale has not been called - which is a very frequent case -
+ the value of GetThreadLocale() ignores past calls to 'setlocale'. */
+ return NULL;
+}
+
+/* XPG3 defines the result of 'setlocale (category, NULL)' as:
+ "Directs 'setlocale()' to query 'category' and return the current
+ setting of 'local'."
+ However it does not specify the exact format. Neither do SUSV2 and
+ ISO C 99. So we can use this feature only on selected systems (e.g.
+ those using GNU C Library). */
+#if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
+# define HAVE_LOCALE_NULL
+#endif
+
+const char *
+gl_locale_name_posix (int category, const char *categoryname)
+{
+#if defined WINDOWS_NATIVE
if (LC_MIN <= category && category <= LC_MAX)
{
char *locname = setlocale (category, NULL);
@@ -2784,8 +2825,8 @@ gl_locale_name_thread (int category, const char *categoryname)
separated list of locales. We need only one, so we take the
one corresponding to LC_CTYPE, as the most important for
character translations. */
- if (strchr (locname, ';'))
- locname = setlocale (LC_CTYPE, NULL);
+ if (category == LC_ALL && strchr (locname, ';'))
+ locname = setlocale (LC_CTYPE, NULL);
/* Convert locale name to LCID. We don't want to use
LocaleNameToLCID because (a) it is only available since Vista,
@@ -2796,22 +2837,6 @@ gl_locale_name_thread (int category, const char *categoryname)
return gl_locale_name_from_win32_LCID (lcid);
}
#endif
- return NULL;
-}
-
-/* XPG3 defines the result of 'setlocale (category, NULL)' as:
- "Directs 'setlocale()' to query 'category' and return the current
- setting of 'local'."
- However it does not specify the exact format. Neither do SUSV2 and
- ISO C 99. So we can use this feature only on selected systems (e.g.
- those using GNU C Library). */
-#if defined _LIBC || ((defined __GLIBC__ && __GLIBC__ >= 2) && !defined __UCLIBC__)
-# define HAVE_LOCALE_NULL
-#endif
-
-const char *
-gl_locale_name_posix (int category, const char *categoryname)
-{
/* Use the POSIX methods of looking to 'LC_ALL', 'LC_xxx', and 'LANG'.
On some systems this can be done by the 'setlocale' function itself. */
#if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL