blob: b16caf44e6bf298b9f145fac9456d2b69f180ab7 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#include <locale.h>
2#include <langinfo.h>
Rich Felker4c485012014-07-02 21:46:41 -04003#include "locale_impl.h"
Rich Felker56000882011-04-03 19:51:14 -04004#include "libc.h"
Rich Felker0b44a032011-02-12 00:22:29 -05005
6static const char c_time[] =
7 "Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0"
8 "Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0"
9 "Thursday\0" "Friday\0" "Saturday\0"
10 "Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0"
11 "Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0"
12 "January\0" "February\0" "March\0" "April\0"
13 "May\0" "June\0" "July\0" "August\0"
14 "September\0" "October\0" "November\0" "December\0"
15 "AM\0" "PM\0"
16 "%a %b %e %T %Y\0"
17 "%m/%d/%y\0"
18 "%H:%M:%S\0"
19 "%I:%M:%S %p\0"
20 "\0"
Rich Felkera19cd2b2014-07-26 02:42:33 -040021 "\0"
Rich Felker0b44a032011-02-12 00:22:29 -050022 "%m/%d/%y\0"
Rich Felkera19cd2b2014-07-26 02:42:33 -040023 "0123456789\0"
Rich Felker0b44a032011-02-12 00:22:29 -050024 "%a %b %e %T %Y\0"
25 "%H:%M:%S";
26
Rich Felker0206f592014-07-26 04:43:50 -040027static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no";
Rich Felker0b44a032011-02-12 00:22:29 -050028static const char c_numeric[] = ".\0" "";
29
Rich Felker87be54a2013-07-24 18:52:02 -040030char *__nl_langinfo_l(nl_item item, locale_t loc)
Rich Felker0b44a032011-02-12 00:22:29 -050031{
32 int cat = item >> 16;
33 int idx = item & 65535;
34 const char *str;
35
Rich Felker2d51c4a2015-10-01 22:59:56 +000036 if (item == CODESET) return MB_CUR_MAX==1 ? "ASCII" : "UTF-8";
Rich Felker947d3302017-07-31 23:08:27 -040037
38 /* _NL_LOCALE_NAME extension */
39 if (idx == 65535 && cat < LC_ALL)
40 return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
Rich Felker0b44a032011-02-12 00:22:29 -050041
42 switch (cat) {
43 case LC_NUMERIC:
Rich Felkera946e812015-11-10 23:07:17 -050044 if (idx > 1) return "";
Rich Felker0b44a032011-02-12 00:22:29 -050045 str = c_numeric;
46 break;
47 case LC_TIME:
Rich Felkera946e812015-11-10 23:07:17 -050048 if (idx > 0x31) return "";
Rich Felker0b44a032011-02-12 00:22:29 -050049 str = c_time;
50 break;
51 case LC_MONETARY:
Rich Felkera946e812015-11-10 23:07:17 -050052 if (idx > 0) return "";
Rich Felker0b44a032011-02-12 00:22:29 -050053 str = "";
54 break;
55 case LC_MESSAGES:
Rich Felkera946e812015-11-10 23:07:17 -050056 if (idx > 3) return "";
Rich Felker0b44a032011-02-12 00:22:29 -050057 str = c_messages;
58 break;
59 default:
Rich Felkera946e812015-11-10 23:07:17 -050060 return "";
Rich Felker0b44a032011-02-12 00:22:29 -050061 }
62
63 for (; idx; idx--, str++) for (; *str; str++);
Rich Felkerc5b8f192014-07-26 05:36:25 -040064 if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc);
Rich Felker56000882011-04-03 19:51:14 -040065 return (char *)str;
Rich Felker0b44a032011-02-12 00:22:29 -050066}
Rich Felker56000882011-04-03 19:51:14 -040067
Rich Felker87be54a2013-07-24 18:52:02 -040068char *__nl_langinfo(nl_item item)
69{
Rich Felker4c485012014-07-02 21:46:41 -040070 return __nl_langinfo_l(item, CURRENT_LOCALE);
Rich Felker87be54a2013-07-24 18:52:02 -040071}
72
73weak_alias(__nl_langinfo, nl_langinfo);
74weak_alias(__nl_langinfo_l, nl_langinfo_l);