1 #include <locale.h>
2 #include <limits.h>
3 #include <string.h>
4
5 static struct lconv Clocale = {
6 ".", /* decimal_point */
7 "", /* thousands_sep */
8 "", /* grouping */
9 "", /* int_curr_symbol */
10 "", /* currency_symbol */
11 "", /* mon_decimal_point */
12 "", /* mon_thousands_sep */
13 "", /* mon_grouping */
14 "", /* positive_sign */
15 "", /* negative_sign */
16 CHAR_MAX, /* int_frac_digits */
17 CHAR_MAX, /* frac_digits */
18 CHAR_MAX, /* p_cs_precedes */
19 CHAR_MAX, /* p_sep_by_space */
20 CHAR_MAX, /* n_cs_precedes */
21 CHAR_MAX, /* n_sep_by_space */
22 CHAR_MAX, /* p_sign_posn */
23 CHAR_MAX, /* n_sign_posn */
24 };
25
26 static char *localename[2] = {"C", ""};
27 static short catlocale[6] = {0, 0, 0, 0, 0, 0};
28 /* indices into localename for categories LC_ALL, LC_COLLATE, etc. */
29
30 #define ASIZE(a) (sizeof(a)/sizeof(a[0]))
31
32 char *
setlocale(int category,const char * locale)33 setlocale(int category, const char *locale)
34 {
35 int c, i;
36
37 if(category < 0 || category >= ASIZE(catlocale))
38 return 0;
39 if(!locale)
40 return localename[catlocale[category]];
41 for(c=0; c<ASIZE(localename); c++)
42 if(strcmp(locale, localename[c]) == 0)
43 break;
44 if(c >= ASIZE(localename))
45 return 0;
46 catlocale[category] = c;
47 if(category == LC_ALL)
48 for(i=0; i<ASIZE(catlocale); i++)
49 catlocale[i] = c;
50 return localename[c];
51 }
52
53 struct lconv *
localeconv(void)54 localeconv(void)
55 {
56 /* BUG: posix says look at environment variables
57 * to set locale "", but we just make it the same
58 * as C, always.
59 */
60 return &Clocale;
61 }
62
63