1 #include <locale.h>
2 #include <langinfo.h>
3 #include "libc.h"
4 
5 static const char c_time[] =
6 	"Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0"
7 	"Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0"
8 	"Thursday\0" "Friday\0" "Saturday\0"
9 	"Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0"
10 	"Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0"
11 	"January\0"   "February\0" "March\0"    "April\0"
12 	"May\0"       "June\0"     "July\0"     "August\0"
13 	"September\0" "October\0"  "November\0" "December\0"
14 	"AM\0" "PM\0"
15 	"%a %b %e %T %Y\0"
16 	"%m/%d/%y\0"
17 	"%H:%M:%S\0"
18 	"%I:%M:%S %p\0"
19 	"\0"
20 	"%m/%d/%y\0"
21 	"0123456789"
22 	"%a %b %e %T %Y\0"
23 	"%H:%M:%S";
24 
25 static const char c_messages[] = "^[yY]\0" "^[nN]";
26 static const char c_numeric[] = ".\0" "";
27 
28 // Android: this was __nl_langinfo_l in musl.
nl_langinfo_l(nl_item item,locale_t loc)29 char *nl_langinfo_l(nl_item item, locale_t loc)
30 {
31 	int cat = item >> 16;
32 	int idx = item & 65535;
33 	const char *str;
34 
35 	if (item == CODESET) return "UTF-8";
36 
37 	switch (cat) {
38 	case LC_NUMERIC:
39 		if (idx > 1) return NULL;
40 		str = c_numeric;
41 		break;
42 	case LC_TIME:
43 		if (idx > 0x31) return NULL;
44 		str = c_time;
45 		break;
46 	case LC_MONETARY:
47 		if (idx > 0) return NULL;
48 		str = "";
49 		break;
50 	case LC_MESSAGES:
51 		if (idx > 1) return NULL;
52 		str = c_messages;
53 		break;
54 	default:
55 		return NULL;
56 	}
57 
58 	for (; idx; idx--, str++) for (; *str; str++);
59 	return (char *)str;
60 }
61 
62 // Android: this was __nl_langinfo in musl
nl_langinfo(nl_item item)63 char *nl_langinfo(nl_item item)
64 {
65 	return nl_langinfo_l(item, 0);
66 }
67 
68 weak_alias(__nl_langinfo, nl_langinfo);
69 weak_alias(__nl_langinfo_l, nl_langinfo_l);
70