summaryrefslogtreecommitdiffstats
path: root/lib/libc/locale/common_setlocale.c
blob: 2dd549f303e27458a1f56c4828769d9ed8b5f55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <locale.h>
#include <string.h>

/*
 * Category names for getenv()
 */
char *_categories[_LC_LAST] = {
    "LC_ALL",
    "LC_COLLATE",
    "LC_CTYPE",
    "LC_MONETARY",
    "LC_NUMERIC",
    "LC_TIME",
};

/*
 * Current locales for each category
 */
char _current_categories[_LC_LAST][32] = {
    "C",
    "C",
    "C",
    "C",
    "C",
    "C",
};

/*
 * The locales we are going to try and load
 */
char _new_categories[_LC_LAST][32];

char _current_locale_string[_LC_LAST * 33];

char *
_currentlocale()
{
	int i, len;

	(void)strcpy(_current_locale_string, _current_categories[1]);

	for (i = 2; i < _LC_LAST; ++i)
		if (strcmp(_current_categories[1], _current_categories[i])) {
			len = strlen(_current_categories[1]) + 1 +
			      strlen(_current_categories[2]) + 1 +
			      strlen(_current_categories[3]) + 1 +
			      strlen(_current_categories[4]) + 1 +
			      strlen(_current_categories[5]) + 1;
			if (len > sizeof(_current_locale_string))
				return NULL;
			(void) strcpy(_current_locale_string, _current_categories[1]);
			(void) strcat(_current_locale_string, "/");
			(void) strcat(_current_locale_string, _current_categories[2]);
			(void) strcat(_current_locale_string, "/");
			(void) strcat(_current_locale_string, _current_categories[3]);
			(void) strcat(_current_locale_string, "/");
			(void) strcat(_current_locale_string, _current_categories[4]);
			(void) strcat(_current_locale_string, "/");
			(void) strcat(_current_locale_string, _current_categories[5]);
			break;
		}
	return (_current_locale_string);
}

OpenPOWER on IntegriCloud