Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/locale/xlocale.c
Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | static int dupcomponent(int type, locale_t base, locale_t new) | ||||
*/ | */ | ||||
struct xlocale_component *src = base->components[type]; | struct xlocale_component *src = base->components[type]; | ||||
if (&__xlocale_global_locale == base) { | if (&__xlocale_global_locale == base) { | ||||
new->components[type] = constructors[type](src->locale, new); | new->components[type] = constructors[type](src->locale, new); | ||||
if (new->components[type]) { | if (new->components[type]) { | ||||
strncpy(new->components[type]->locale, src->locale, | strncpy(new->components[type]->locale, src->locale, | ||||
ENCODING_LEN); | ENCODING_LEN); | ||||
strncpy(new->components[type]->version, src->version, | |||||
XLOCALE_VERSION_LEN); | |||||
} | } | ||||
} else if (base->components[type]) { | } else if (base->components[type]) { | ||||
new->components[type] = xlocale_retain(base->components[type]); | new->components[type] = xlocale_retain(base->components[type]); | ||||
} else { | } else { | ||||
/* If the component was NULL, return success - if base is a | /* If the component was NULL, return success - if base is a | ||||
* valid locale then the flag indicating that this isn't | * valid locale then the flag indicating that this isn't | ||||
* present should be set. If it isn't a valid locale, then | * present should be set. If it isn't a valid locale, then | ||||
* we're stuck anyway. */ | * we're stuck anyway. */ | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | freelocale(locale_t loc) | ||||
* actually do anything. | * actually do anything. | ||||
*/ | */ | ||||
if (loc != NULL && loc != LC_GLOBAL_LOCALE && | if (loc != NULL && loc != LC_GLOBAL_LOCALE && | ||||
loc != &__xlocale_global_locale) | loc != &__xlocale_global_locale) | ||||
xlocale_release(loc); | xlocale_release(loc); | ||||
} | } | ||||
/* | /* | ||||
* Returns the name of the locale for a particular component of a locale_t. | * Returns the name or version of the locale for a particular component of a | ||||
* locale_t. | |||||
*/ | */ | ||||
const char *querylocale(int mask, locale_t loc) | const char *querylocale(int mask, locale_t loc) | ||||
{ | { | ||||
int type = ffs(mask) - 1; | int type = ffs(mask & ~LC_VERSION_MASK) - 1; | ||||
FIX_LOCALE(loc); | FIX_LOCALE(loc); | ||||
if (type >= XLC_LAST) | if (type >= XLC_LAST) | ||||
return (NULL); | return (NULL); | ||||
if (mask & LC_VERSION_MASK) { | |||||
if (loc->components[type]) | if (loc->components[type]) | ||||
return (loc->components[type]->version); | |||||
return (""); | |||||
} else { | |||||
if (loc->components[type]) | |||||
return (loc->components[type]->locale); | return (loc->components[type]->locale); | ||||
return ("C"); | return ("C"); | ||||
} | |||||
} | } | ||||
/* | /* | ||||
* Installs the specified locale_t as this thread's locale. | * Installs the specified locale_t as this thread's locale. | ||||
*/ | */ | ||||
locale_t uselocale(locale_t loc) | locale_t uselocale(locale_t loc) | ||||
{ | { | ||||
locale_t old = get_thread_locale(); | locale_t old = get_thread_locale(); | ||||
if (NULL != loc) { | if (NULL != loc) { | ||||
set_thread_locale(loc); | set_thread_locale(loc); | ||||
} | } | ||||
return (old ? old : LC_GLOBAL_LOCALE); | return (old ? old : LC_GLOBAL_LOCALE); | ||||
} | } | ||||