X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fduplocale.c;h=54a14fd21b35bec6868f6720421cd6fc40a5a757;hb=893f75bfc4d025e22075e1c441e594cc6b738066;hp=63d00d9a6c8fa39ad84fb976c1acd267682a3e19;hpb=3f0d472e052865baf722ea457e35dd067b94a477;p=gnulib.git diff --git a/lib/duplocale.c b/lib/duplocale.c index 63d00d9a6..54a14fd21 100644 --- a/lib/duplocale.c +++ b/lib/duplocale.c @@ -1,5 +1,5 @@ /* Duplicate a locale object. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,15 +22,8 @@ #include #include -#include #include -/* Work around an incorrect definition of the _NL_LOCALE_NAME macro in - glibc < 2.12. - See . */ -#undef _NL_LOCALE_NAME -#define _NL_LOCALE_NAME(category) _NL_ITEM ((category), _NL_ITEM_INDEX (-1)) - #define SIZEOF(a) (sizeof(a) / sizeof(a[0])) #undef duplocale @@ -39,64 +32,68 @@ locale_t rpl_duplocale (locale_t locale) { /* Work around crash in the duplocale function in glibc < 2.12. - See . */ + See . + Also, on AIX 7.1, duplocale(LC_GLOBAL_LOCALE) returns (locale_t)0 with + errno set to EINVAL. */ if (locale == LC_GLOBAL_LOCALE) { /* Create a copy of the locale by fetching the name of each locale - category, starting with LC_CTYPE. */ - static struct { int cat; int mask; } categories[] = - { - { LC_NUMERIC, LC_NUMERIC_MASK }, - { LC_TIME, LC_TIME_MASK }, - { LC_COLLATE, LC_COLLATE_MASK }, - { LC_MONETARY, LC_MONETARY_MASK }, - { LC_MESSAGES, LC_MESSAGES_MASK } + category, starting with LC_CTYPE. */ + static struct { int cat; int mask; } const categories[] = + { + { LC_NUMERIC, LC_NUMERIC_MASK }, + { LC_TIME, LC_TIME_MASK }, + { LC_COLLATE, LC_COLLATE_MASK }, + { LC_MONETARY, LC_MONETARY_MASK }, + { LC_MESSAGES, LC_MESSAGES_MASK } #ifdef LC_PAPER - , { LC_PAPER, LC_PAPER_MASK } + , { LC_PAPER, LC_PAPER_MASK } #endif #ifdef LC_NAME - , { LC_NAME, LC_NAME_MASK } + , { LC_NAME, LC_NAME_MASK } #endif #ifdef LC_ADDRESS - , { LC_ADDRESS, LC_ADDRESS_MASK } + , { LC_ADDRESS, LC_ADDRESS_MASK } #endif #ifdef LC_TELEPHONE - , { LC_TELEPHONE, LC_TELEPHONE_MASK } + , { LC_TELEPHONE, LC_TELEPHONE_MASK } #endif #ifdef LC_MEASUREMENT - , { LC_MEASUREMENT, LC_MEASUREMENT_MASK } + , { LC_MEASUREMENT, LC_MEASUREMENT_MASK } #endif #ifdef LC_IDENTIFICATION - , { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } + , { 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 = setlocale (LC_CTYPE, NULL); + base_copy = newlocale (LC_ALL_MASK, base_name, NULL); if (base_copy == NULL) - return NULL; + return NULL; for (i = 0; i < SIZEOF (categories); i++) - { - int category = categories[i].cat; - int category_mask = categories[i].mask; - const char *name = nl_langinfo (_NL_LOCALE_NAME (category)); - if (strcmp (name, base_name) != 0) - { - locale_t copy = newlocale (category_mask, name, base_copy); - if (copy == NULL) - { - int saved_errno = errno; - freelocale (base_copy); - errno = saved_errno; - return NULL; - } - /* No need to call freelocale (base_copy) if copy != base_copy; - the newlocale function already takes care of doing it. */ - base_copy = copy; - } - } + { + int category = categories[i].cat; + int category_mask = categories[i].mask; + const char *name = setlocale (category, NULL); + if (strcmp (name, base_name) != 0) + { + locale_t copy = newlocale (category_mask, name, base_copy); + if (copy == NULL) + { + int saved_errno = errno; + freelocale (base_copy); + errno = saved_errno; + return NULL; + } + /* No need to call freelocale (base_copy) if copy != base_copy; + the newlocale function already takes care of doing it. */ + base_copy = copy; + } + } return base_copy; }