langinfo.c 1.8 KB
Newer Older
R
Rich Felker 已提交
1 2
#include <locale.h>
#include <langinfo.h>
W
w00349915 已提交
3
#include <unsupported_api.h>
4
#include "locale_impl.h"
R
Rich Felker 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

static const char c_time[] =
	"Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0"
	"Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0"
	"Thursday\0" "Friday\0" "Saturday\0"
	"Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0"
	"Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0"
	"January\0"   "February\0" "March\0"    "April\0"
	"May\0"       "June\0"     "July\0"     "August\0"
	"September\0" "October\0"  "November\0" "December\0"
	"AM\0" "PM\0"
	"%a %b %e %T %Y\0"
	"%m/%d/%y\0"
	"%H:%M:%S\0"
	"%I:%M:%S %p\0"
	"\0"
21
	"\0"
R
Rich Felker 已提交
22
	"%m/%d/%y\0"
23
	"0123456789\0"
R
Rich Felker 已提交
24 25 26
	"%a %b %e %T %Y\0"
	"%H:%M:%S";

27
static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no";
R
Rich Felker 已提交
28 29
static const char c_numeric[] = ".\0" "";

30
char *__nl_langinfo_l(nl_item item, locale_t loc)
R
Rich Felker 已提交
31 32 33 34 35
{
	int cat = item >> 16;
	int idx = item & 65535;
	const char *str;

W
w00349915 已提交
36 37
	unsupported_api(__FUNCTION__);

38
	if (item == CODESET) return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII";
39 40 41 42

	/* _NL_LOCALE_NAME extension */
	if (idx == 65535 && cat < LC_ALL)
		return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
W
w00349915 已提交
43

R
Rich Felker 已提交
44 45
	switch (cat) {
	case LC_NUMERIC:
46
		if (idx > 1) return "";
R
Rich Felker 已提交
47 48 49
		str = c_numeric;
		break;
	case LC_TIME:
50
		if (idx > 0x31) return "";
R
Rich Felker 已提交
51 52 53
		str = c_time;
		break;
	case LC_MONETARY:
54
		if (idx > 0) return "";
R
Rich Felker 已提交
55 56 57
		str = "";
		break;
	case LC_MESSAGES:
58
		if (idx > 3) return "";
R
Rich Felker 已提交
59 60 61
		str = c_messages;
		break;
	default:
62
		return "";
R
Rich Felker 已提交
63 64 65
	}

	for (; idx; idx--, str++) for (; *str; str++);
66
	if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc);
67
	return (char *)str;
R
Rich Felker 已提交
68
}
69

70 71
char *__nl_langinfo(nl_item item)
{
W
w00349915 已提交
72
	unsupported_api(__FUNCTION__);
73
	return __nl_langinfo_l(item, CURRENT_LOCALE);
74 75 76 77
}

weak_alias(__nl_langinfo, nl_langinfo);
weak_alias(__nl_langinfo_l, nl_langinfo_l);