1 --- nl_langinfo.c.orig 2008-01-15 11:30:57.000000000 -0800
2 +++ nl_langinfo.c 2008-01-17 23:58:24.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.17 2003/06/26 10:46:16 phantom Exp $");
7 +#include "xlocale_private.h"
14 #include "lmessages.h"
15 #include "lmonetary.h"
16 -#include "../stdtime/timelocal.h"
17 +#include "timelocal.h"
19 #define _REL(BASE) ((int)item-BASE)
22 -nl_langinfo(nl_item item)
23 +nl_langinfo_l(nl_item item, locale_t loc)
28 static char *csym = NULL;
30 + NORMALIZE_LOCALE(loc);
34 - if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
35 + if ((s = querylocale(LC_CTYPE_MASK, loc)) != NULL) {
36 if ((cs = strchr(s, '.')) != NULL)
38 else if (strcmp(s, "C") == 0 ||
39 strcmp(s, "POSIX") == 0)
41 + else if (strcmp(s, "UTF-8") == 0)
46 - ret = (char *) __get_current_time_locale()->c_fmt;
47 + ret = (char *) __get_current_time_locale(loc)->c_fmt;
50 - ret = (char *) __get_current_time_locale()->x_fmt;
51 + ret = (char *) __get_current_time_locale(loc)->x_fmt;
54 - ret = (char *) __get_current_time_locale()->X_fmt;
55 + ret = (char *) __get_current_time_locale(loc)->X_fmt;
58 - ret = (char *) __get_current_time_locale()->ampm_fmt;
59 + ret = (char *) __get_current_time_locale(loc)->ampm_fmt;
62 - ret = (char *) __get_current_time_locale()->am;
63 + ret = (char *) __get_current_time_locale(loc)->am;
66 - ret = (char *) __get_current_time_locale()->pm;
67 + ret = (char *) __get_current_time_locale(loc)->pm;
69 case DAY_1: case DAY_2: case DAY_3:
70 case DAY_4: case DAY_5: case DAY_6: case DAY_7:
71 - ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)];
72 + ret = (char*) __get_current_time_locale(loc)->weekday[_REL(DAY_1)];
74 case ABDAY_1: case ABDAY_2: case ABDAY_3:
75 case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7:
76 - ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)];
77 + ret = (char*) __get_current_time_locale(loc)->wday[_REL(ABDAY_1)];
79 case MON_1: case MON_2: case MON_3: case MON_4:
80 case MON_5: case MON_6: case MON_7: case MON_8:
81 case MON_9: case MON_10: case MON_11: case MON_12:
82 - ret = (char*) __get_current_time_locale()->month[_REL(MON_1)];
83 + ret = (char*) __get_current_time_locale(loc)->month[_REL(MON_1)];
85 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4:
86 case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8:
87 case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12:
88 - ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)];
89 + ret = (char*) __get_current_time_locale(loc)->mon[_REL(ABMON_1)];
92 /* XXX: need to be implemented */
97 - ret = (char*) __get_current_numeric_locale()->decimal_point;
98 + ret = (char*) __get_current_numeric_locale(loc)->decimal_point;
101 - ret = (char*) __get_current_numeric_locale()->thousands_sep;
102 + ret = (char*) __get_current_numeric_locale(loc)->thousands_sep;
105 - ret = (char*) __get_current_messages_locale()->yesexpr;
106 + ret = (char*) __get_current_messages_locale(loc)->yesexpr;
109 - ret = (char*) __get_current_messages_locale()->noexpr;
110 + ret = (char*) __get_current_messages_locale(loc)->noexpr;
113 * YESSTR and NOSTR items marked with LEGACY are available, but not
114 @@ -131,25 +137,25 @@
115 * they're subject to remove in future specification editions.
117 case YESSTR: /* LEGACY */
118 - ret = (char*) __get_current_messages_locale()->yesstr;
119 + ret = (char*) __get_current_messages_locale(loc)->yesstr;
121 case NOSTR: /* LEGACY */
122 - ret = (char*) __get_current_messages_locale()->nostr;
123 + ret = (char*) __get_current_messages_locale(loc)->nostr;
126 * SUSv2 special formatted currency string
130 - cs = (char*) __get_current_monetary_locale()->currency_symbol;
131 + cs = (char*) __get_current_monetary_locale(loc)->currency_symbol;
133 - char pos = localeconv()->p_cs_precedes;
134 + char pos = localeconv_l(loc)->p_cs_precedes;
136 - if (pos == localeconv()->n_cs_precedes) {
137 + if (pos == localeconv_l(loc)->n_cs_precedes) {
140 if (pos == CHAR_MAX) {
141 - if (strcmp(cs, __get_current_monetary_locale()->mon_decimal_point) == 0)
142 + if (strcmp(cs, __get_current_monetary_locale(loc)->mon_decimal_point) == 0)
145 psn = pos ? '-' : '+';
146 @@ -166,10 +172,19 @@
149 case D_MD_ORDER: /* FreeBSD local extension */
150 - ret = (char *) __get_current_time_locale()->md_order;
151 + ret = (char *) __get_current_time_locale(loc)->md_order;
155 + return ""; /* do not consult POSIX */
157 + if (ret && !ret[0] && item != D_MD_ORDER && item != CODESET && loc != _c_locale) {
158 + ret = nl_langinfo_l(item, _c_locale);
164 +nl_langinfo(nl_item item)
166 + return (nl_langinfo_l(item, __current_locale()));