1 #include <locale.h> 2 #include <langinfo.h> 3 #include "locale_impl.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 "\0" 21 "%m/%d/%y\0" 22 "0123456789\0" 23 "%a %b %e %T %Y\0" 24 "%H:%M:%S"; 25 26 static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no"; 27 static const char c_numeric[] = ".\0" ""; 28 __nl_langinfo_l(nl_item item,locale_t loc)29char *__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 loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII"; 36 37 /* _NL_LOCALE_NAME extension */ 38 if (idx == 65535 && cat < LC_ALL) 39 return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C"; 40 41 switch (cat) { 42 case LC_NUMERIC: 43 if (idx > 1) return ""; 44 str = c_numeric; 45 break; 46 case LC_TIME: 47 if (idx > 0x31) return ""; 48 str = c_time; 49 break; 50 case LC_MONETARY: 51 if (idx > 0) return ""; 52 str = ""; 53 break; 54 case LC_MESSAGES: 55 if (idx > 3) return ""; 56 str = c_messages; 57 break; 58 default: 59 return ""; 60 } 61 62 for (; idx; idx--, str++) for (; *str; str++); 63 if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc); 64 return (char *)str; 65 } 66 __nl_langinfo(nl_item item)67char *__nl_langinfo(nl_item item) 68 { 69 return __nl_langinfo_l(item, CURRENT_LOCALE); 70 } 71 72 weak_alias(__nl_langinfo, nl_langinfo); 73 weak_alias(__nl_langinfo_l, nl_langinfo_l); 74