]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/nl_langinfo.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / locale / FreeBSD / nl_langinfo.c.patch
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
3 @@ -27,6 +27,8 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/nl_langinfo.c,v 1.17 2003/06/26 10:46:16 phantom Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <langinfo.h>
10 #include <limits.h>
11 #include <locale.h>
12 @@ -36,62 +38,66 @@
13 #include "lnumeric.h"
14 #include "lmessages.h"
15 #include "lmonetary.h"
16 -#include "../stdtime/timelocal.h"
17 +#include "timelocal.h"
18
19 #define _REL(BASE) ((int)item-BASE)
20
21 char *
22 -nl_langinfo(nl_item item)
23 +nl_langinfo_l(nl_item item, locale_t loc)
24 {
25 - char *ret, *s, *cs;
26 + char *ret, *cs;
27 + const char *s;
28 static char *csym = NULL;
29
30 + NORMALIZE_LOCALE(loc);
31 switch (item) {
32 case CODESET:
33 ret = "";
34 - if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
35 + if ((s = querylocale(LC_CTYPE_MASK, loc)) != NULL) {
36 if ((cs = strchr(s, '.')) != NULL)
37 ret = cs + 1;
38 else if (strcmp(s, "C") == 0 ||
39 strcmp(s, "POSIX") == 0)
40 ret = "US-ASCII";
41 + else if (strcmp(s, "UTF-8") == 0)
42 + ret = "UTF-8";
43 }
44 break;
45 case D_T_FMT:
46 - ret = (char *) __get_current_time_locale()->c_fmt;
47 + ret = (char *) __get_current_time_locale(loc)->c_fmt;
48 break;
49 case D_FMT:
50 - ret = (char *) __get_current_time_locale()->x_fmt;
51 + ret = (char *) __get_current_time_locale(loc)->x_fmt;
52 break;
53 case T_FMT:
54 - ret = (char *) __get_current_time_locale()->X_fmt;
55 + ret = (char *) __get_current_time_locale(loc)->X_fmt;
56 break;
57 case T_FMT_AMPM:
58 - ret = (char *) __get_current_time_locale()->ampm_fmt;
59 + ret = (char *) __get_current_time_locale(loc)->ampm_fmt;
60 break;
61 case AM_STR:
62 - ret = (char *) __get_current_time_locale()->am;
63 + ret = (char *) __get_current_time_locale(loc)->am;
64 break;
65 case PM_STR:
66 - ret = (char *) __get_current_time_locale()->pm;
67 + ret = (char *) __get_current_time_locale(loc)->pm;
68 break;
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)];
73 break;
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)];
78 break;
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)];
84 break;
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)];
90 break;
91 case ERA:
92 /* XXX: need to be implemented */
93 @@ -114,16 +120,16 @@
94 ret = "";
95 break;
96 case RADIXCHAR:
97 - ret = (char*) __get_current_numeric_locale()->decimal_point;
98 + ret = (char*) __get_current_numeric_locale(loc)->decimal_point;
99 break;
100 case THOUSEP:
101 - ret = (char*) __get_current_numeric_locale()->thousands_sep;
102 + ret = (char*) __get_current_numeric_locale(loc)->thousands_sep;
103 break;
104 case YESEXPR:
105 - ret = (char*) __get_current_messages_locale()->yesexpr;
106 + ret = (char*) __get_current_messages_locale(loc)->yesexpr;
107 break;
108 case NOEXPR:
109 - ret = (char*) __get_current_messages_locale()->noexpr;
110 + ret = (char*) __get_current_messages_locale(loc)->noexpr;
111 break;
112 /*
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.
116 */
117 case YESSTR: /* LEGACY */
118 - ret = (char*) __get_current_messages_locale()->yesstr;
119 + ret = (char*) __get_current_messages_locale(loc)->yesstr;
120 break;
121 case NOSTR: /* LEGACY */
122 - ret = (char*) __get_current_messages_locale()->nostr;
123 + ret = (char*) __get_current_messages_locale(loc)->nostr;
124 break;
125 /*
126 * SUSv2 special formatted currency string
127 */
128 case CRNCYSTR:
129 ret = "";
130 - cs = (char*) __get_current_monetary_locale()->currency_symbol;
131 + cs = (char*) __get_current_monetary_locale(loc)->currency_symbol;
132 if (*cs != '\0') {
133 - char pos = localeconv()->p_cs_precedes;
134 + char pos = localeconv_l(loc)->p_cs_precedes;
135
136 - if (pos == localeconv()->n_cs_precedes) {
137 + if (pos == localeconv_l(loc)->n_cs_precedes) {
138 char psn = '\0';
139
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)
143 psn = '.';
144 } else
145 psn = pos ? '-' : '+';
146 @@ -166,10 +172,19 @@
147 }
148 break;
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;
152 break;
153 default:
154 - ret = "";
155 + return ""; /* do not consult POSIX */
156 + }
157 + if (ret && !ret[0] && item != D_MD_ORDER && item != CODESET && loc != _c_locale) {
158 + ret = nl_langinfo_l(item, _c_locale);
159 }
160 return (ret);
161 }
162 +
163 +char *
164 +nl_langinfo(nl_item item)
165 +{
166 + return (nl_langinfo_l(item, __current_locale()));
167 +}