locale: Implement getlocalename_l.
Specified in POSIX-2024. GNUlib currently has a nasty Haiku-specific hack to implement equivalent functionality; after this it should be able to use this function instead.
This commit is contained in:
@@ -66,13 +66,14 @@ struct lconv {
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern struct lconv *localeconv(void);
|
|
||||||
extern char *setlocale(int category, const char *locale);
|
extern char *setlocale(int category, const char *locale);
|
||||||
|
extern struct lconv *localeconv(void);
|
||||||
|
|
||||||
extern locale_t duplocale(locale_t);
|
extern locale_t duplocale(locale_t);
|
||||||
extern void freelocale(locale_t);
|
extern void freelocale(locale_t);
|
||||||
extern locale_t newlocale(int, const char *, locale_t);
|
extern locale_t newlocale(int, const char *, locale_t);
|
||||||
extern locale_t uselocale(locale_t);
|
extern locale_t uselocale(locale_t);
|
||||||
|
const char *getlocalename_l(int category, locale_t locobj);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,6 +260,17 @@ uselocale(locale_t newLoc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" const char*
|
||||||
|
getlocalename_l(int category, locale_t l)
|
||||||
|
{
|
||||||
|
LocaleBackend* backend = (l == LC_GLOBAL_LOCALE) ?
|
||||||
|
gGlobalLocaleBackend : (LocaleBackend*)((LocaleBackendData*)l)->backend;
|
||||||
|
if (backend == NULL)
|
||||||
|
return "POSIX";
|
||||||
|
return backend->SetLocale(category, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" locale_t
|
extern "C" locale_t
|
||||||
__current_locale_t()
|
__current_locale_t()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,13 +28,8 @@ setlocale(int category, const char* locale)
|
|||||||
if (category < 0 || category > LC_LAST)
|
if (category < 0 || category > LC_LAST)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (locale == NULL) {
|
if (locale == NULL)
|
||||||
// query the locale of the given category
|
return const_cast<char*>(getlocalename_l(category, LC_GLOBAL_LOCALE));
|
||||||
if (gGlobalLocaleBackend != NULL)
|
|
||||||
return const_cast<char*>(gGlobalLocaleBackend->SetLocale(category, NULL));
|
|
||||||
else
|
|
||||||
return const_cast<char*>("POSIX");
|
|
||||||
}
|
|
||||||
|
|
||||||
// we may have to invoke SetLocale once for each category, so we use an
|
// we may have to invoke SetLocale once for each category, so we use an
|
||||||
// array to collect the locale per category
|
// array to collect the locale per category
|
||||||
|
|||||||
Reference in New Issue
Block a user