/* Copyright (C) 2008 Emmanuel Varoquaux
This file is part of XOS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
#include
#include
#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, /* LC_CTYPE */
&__locale_C, /* LC_NUMERIC */
&__locale_C, /* LC_TIME */
&__locale_C, /* LC_COLLATE */
&__locale_C, /* LC_MONETARY */
&__locale_C /* LC_ALL */
};
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;
}