#include <locale.h>
#include <string.h>
#define LOCALENAME_MAX 255
struct locale_struct {
char name[LOCALENAME_MAX + 1];
};
static struct locale_struct __locale_C = {
.name = "C"
};
static struct locale_struct *__current_locale[] = {
&__locale_C,
&__locale_C,
&__locale_C,
&__locale_C,
&__locale_C,
&__locale_C
};
static const size_t __category_count = sizeof __current_locale / sizeof __current_locale[0];
static struct locale_struct *__get_locale(const char *name)
{
if (!strcmp(name, "C"))
return &__locale_C;
else if (!strcmp(name, "POSIX"))
return &__locale_C;
else
return NULL;
}
char __attribute__ ((weak, visibility ("default"))) *setlocale(int category, const char *locale)
{
struct locale_struct *_locale;
if (category < 0 || (size_t)category >= __category_count)
return NULL;
if (locale) {
if (!(_locale = __get_locale(locale)))
return NULL;
__current_locale[category] = _locale;
}
return __current_locale[category]->name;
}