Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #include <locale.h> |
| 2 | #include <langinfo.h> |
Rich Felker | 4c48501 | 2014-07-02 21:46:41 -0400 | [diff] [blame] | 3 | #include "locale_impl.h" |
Rich Felker | 5600088 | 2011-04-03 19:51:14 -0400 | [diff] [blame] | 4 | #include "libc.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 5 | |
| 6 | static 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 Felker | a19cd2b | 2014-07-26 02:42:33 -0400 | [diff] [blame] | 21 | "\0" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 22 | "%m/%d/%y\0" |
Rich Felker | a19cd2b | 2014-07-26 02:42:33 -0400 | [diff] [blame] | 23 | "0123456789\0" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 24 | "%a %b %e %T %Y\0" |
| 25 | "%H:%M:%S"; |
| 26 | |
Rich Felker | 0206f59 | 2014-07-26 04:43:50 -0400 | [diff] [blame] | 27 | static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no"; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 28 | static const char c_numeric[] = ".\0" ""; |
| 29 | |
Rich Felker | 87be54a | 2013-07-24 18:52:02 -0400 | [diff] [blame] | 30 | char *__nl_langinfo_l(nl_item item, locale_t loc) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 31 | { |
| 32 | int cat = item >> 16; |
| 33 | int idx = item & 65535; |
| 34 | const char *str; |
| 35 | |
Rich Felker | 2d51c4a | 2015-10-01 22:59:56 +0000 | [diff] [blame] | 36 | if (item == CODESET) return MB_CUR_MAX==1 ? "ASCII" : "UTF-8"; |
Rich Felker | 947d330 | 2017-07-31 23:08:27 -0400 | [diff] [blame] | 37 | |
| 38 | /* _NL_LOCALE_NAME extension */ |
| 39 | if (idx == 65535 && cat < LC_ALL) |
| 40 | return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C"; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 41 | |
| 42 | switch (cat) { |
| 43 | case LC_NUMERIC: |
Rich Felker | a946e81 | 2015-11-10 23:07:17 -0500 | [diff] [blame] | 44 | if (idx > 1) return ""; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 45 | str = c_numeric; |
| 46 | break; |
| 47 | case LC_TIME: |
Rich Felker | a946e81 | 2015-11-10 23:07:17 -0500 | [diff] [blame] | 48 | if (idx > 0x31) return ""; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 49 | str = c_time; |
| 50 | break; |
| 51 | case LC_MONETARY: |
Rich Felker | a946e81 | 2015-11-10 23:07:17 -0500 | [diff] [blame] | 52 | if (idx > 0) return ""; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 53 | str = ""; |
| 54 | break; |
| 55 | case LC_MESSAGES: |
Rich Felker | a946e81 | 2015-11-10 23:07:17 -0500 | [diff] [blame] | 56 | if (idx > 3) return ""; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 57 | str = c_messages; |
| 58 | break; |
| 59 | default: |
Rich Felker | a946e81 | 2015-11-10 23:07:17 -0500 | [diff] [blame] | 60 | return ""; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | for (; idx; idx--, str++) for (; *str; str++); |
Rich Felker | c5b8f19 | 2014-07-26 05:36:25 -0400 | [diff] [blame] | 64 | if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc); |
Rich Felker | 5600088 | 2011-04-03 19:51:14 -0400 | [diff] [blame] | 65 | return (char *)str; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 66 | } |
Rich Felker | 5600088 | 2011-04-03 19:51:14 -0400 | [diff] [blame] | 67 | |
Rich Felker | 87be54a | 2013-07-24 18:52:02 -0400 | [diff] [blame] | 68 | char *__nl_langinfo(nl_item item) |
| 69 | { |
Rich Felker | 4c48501 | 2014-07-02 21:46:41 -0400 | [diff] [blame] | 70 | return __nl_langinfo_l(item, CURRENT_LOCALE); |
Rich Felker | 87be54a | 2013-07-24 18:52:02 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | weak_alias(__nl_langinfo, nl_langinfo); |
| 74 | weak_alias(__nl_langinfo_l, nl_langinfo_l); |