From a88cd6da689757fb5cc0186574f7219e433c767e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 23 Nov 2009 11:05:42 +0100 Subject: [PATCH] duplocale: Add support for glibc 2.3.x. --- ChangeLog | 5 +++++ lib/duplocale.c | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bb6922c47..7b0217c001 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-11-23 Bruno Haible + + duplocale: Add support for glibc 2.3.x. + * lib/duplocale.c (rpl_duplocale): Add fallback code for glibc 2.3.x. + 2009-11-22 Bruno Haible vasnprintf: Tiny optimization. diff --git a/lib/duplocale.c b/lib/duplocale.c index 63d00d9a6c..78819cf531 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -70,10 +70,16 @@ rpl_duplocale (locale_t locale) , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } #endif }; - const char *base_name = nl_langinfo (_NL_LOCALE_NAME (LC_CTYPE)); - locale_t base_copy = newlocale (LC_ALL_MASK, base_name, NULL); + const char *base_name; + locale_t base_copy; unsigned int i; + base_name = nl_langinfo (_NL_LOCALE_NAME (LC_CTYPE)); + if (base_name[0] == '\0') + /* Fallback code for glibc < 2.4, which did not implement + nl_langinfo (_NL_LOCALE_NAME (category)). */ + base_name = setlocale (LC_CTYPE, NULL); + base_copy = newlocale (LC_ALL_MASK, base_name, NULL); if (base_copy == NULL) return NULL; @@ -82,6 +88,10 @@ rpl_duplocale (locale_t locale) int category = categories[i].cat; int category_mask = categories[i].mask; const char *name = nl_langinfo (_NL_LOCALE_NAME (category)); + if (name[0] == '\0') + /* Fallback code for glibc < 2.4, which did not implement + nl_langinfo (_NL_LOCALE_NAME (category)). */ + name = setlocale (category, NULL); if (strcmp (name, base_name) != 0) { locale_t copy = newlocale (category_mask, name, base_copy); -- 2.30.2