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:
Augustin Cavalier
2026-01-07 16:27:46 -05:00
parent 571ec77bf1
commit 713e7b2c54
3 changed files with 15 additions and 8 deletions
@@ -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
__current_locale_t()
{
@@ -28,13 +28,8 @@ setlocale(int category, const char* locale)
if (category < 0 || category > LC_LAST)
return NULL;
if (locale == NULL) {
// query the locale of the given category
if (gGlobalLocaleBackend != NULL)
return const_cast<char*>(gGlobalLocaleBackend->SetLocale(category, NULL));
else
return const_cast<char*>("POSIX");
}
if (locale == NULL)
return const_cast<char*>(getlocalename_l(category, LC_GLOBAL_LOCALE));
// we may have to invoke SetLocale once for each category, so we use an
// array to collect the locale per category