|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h> |
|
|
|
|
|
#include <locale.h> |
|
|
|
#include <errno.h> |
|
#include <string.h> |
|
|
|
#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) |
|
|
|
#undef duplocale |
|
|
|
locale_t |
|
rpl_duplocale (locale_t locale) |
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
if (locale == LC_GLOBAL_LOCALE) |
|
{ |
|
|
|
|
|
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 } |
|
#endif |
|
#ifdef LC_NAME |
|
, { LC_NAME, LC_NAME_MASK } |
|
#endif |
|
#ifdef LC_ADDRESS |
|
, { LC_ADDRESS, LC_ADDRESS_MASK } |
|
#endif |
|
#ifdef LC_TELEPHONE |
|
, { LC_TELEPHONE, LC_TELEPHONE_MASK } |
|
#endif |
|
#ifdef LC_MEASUREMENT |
|
, { LC_MEASUREMENT, LC_MEASUREMENT_MASK } |
|
#endif |
|
#ifdef LC_IDENTIFICATION |
|
, { LC_IDENTIFICATION, LC_IDENTIFICATION_MASK } |
|
#endif |
|
}; |
|
char base_name[SETLOCALE_NULL_MAX]; |
|
int err; |
|
locale_t base_copy; |
|
unsigned int i; |
|
|
|
err = setlocale_null_r (LC_CTYPE, base_name, sizeof (base_name)); |
|
if (err) |
|
{ |
|
errno = err; |
|
return NULL; |
|
} |
|
base_copy = newlocale (LC_ALL_MASK, base_name, NULL); |
|
if (base_copy == NULL) |
|
return NULL; |
|
|
|
for (i = 0; i < SIZEOF (categories); i++) |
|
{ |
|
int category = categories[i].cat; |
|
int category_mask = categories[i].mask; |
|
char name[SETLOCALE_NULL_MAX]; |
|
|
|
err = setlocale_null_r (category, name, sizeof (name)); |
|
if (err) |
|
{ |
|
errno = err; |
|
return 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; |
|
} |
|
|
|
|
|
base_copy = copy; |
|
} |
|
} |
|
|
|
return base_copy; |
|
} |
|
|
|
return duplocale (locale); |
|
} |
|
|