Print this page
2964 need POSIX 2008 locale object support
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/port/locale/nl_langinfo.c
+++ new/usr/src/lib/libc/port/locale/nl_langinfo.c
1 1 /*
2 2 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
3 3 * Copyright (c) 2001, 2003 Alexey Zelkin <phantom@FreeBSD.org>
4 4 * All rights reserved.
5 5 *
6 + * Copyright (c) 2011 The FreeBSD Foundation
7 + * All rights reserved.
8 + * Portions of this software were developed by David Chisnall
9 + * under sponsorship from the FreeBSD Foundation.
10 + *
6 11 * Redistribution and use in source and binary forms, with or without
7 12 * modification, are permitted provided that the following conditions
8 13 * are met:
9 14 * 1. Redistributions of source code must retain the above copyright
10 15 * notice, this list of conditions and the following disclaimer.
11 16 * 2. Redistributions in binary form must reproduce the above copyright
12 17 * notice, this list of conditions and the following disclaimer in the
13 18 * documentation and/or other materials provided with the distribution.
14 19 *
15 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 30 * SUCH DAMAGE.
26 31 */
27 32
28 33 #include "lint.h"
29 34 #include <langinfo.h>
30 35 #include <limits.h>
31 36 #include <locale.h>
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
32 37 #include <stdlib.h>
33 38 #include <string.h>
34 39
35 40 #include "lnumeric.h"
36 41 #include "lmessages.h"
37 42 #include "lmonetary.h"
38 43 #include "timelocal.h"
39 44
40 45 #define _REL(BASE) ((int)item-BASE)
41 46
42 -#define MONETARY (__get_current_monetary_locale())
47 +#define MONETARY (__get_current_monetary_locale(loc))
43 48 #define TIME (__get_current_time_locale())
44 -#define MESSAGES (__get_current_messages_locale())
49 +#define MESSAGES (__get_current_messages_locale(loc)) /* XXX */
45 50 #define NUMERIC (__get_current_numeric_locale())
46 51
47 52 #pragma weak _nl_langinfo = nl_langinfo
48 53
49 54 char *
50 -nl_langinfo(nl_item item)
55 +nl_langinfo_l(nl_item item, locale_t loc)
51 56 {
52 57 char *ret, *s, *cs;
53 58 static char *csym = NULL;
54 59
55 60 switch (item) {
56 61 case CODESET:
57 62 ret = "";
58 63 /*
59 64 * The codeset is the suffix of a locale, for most it will
60 65 * will be UTF-8, as in "en.UTF-8". Short form locales are
61 66 * not supported. Note also that although FreeBSD uses
62 67 * US-ASCII, Solaris historically has reported "646" for the
63 68 * C locale.
64 69 */
65 70 if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
66 71 if ((cs = strchr(s, '.')) != NULL)
67 72 ret = cs + 1;
68 73 else if (strcmp(s, "C") == 0 || strcmp(s, "POSIX") == 0)
69 74 ret = "646";
70 75 }
71 76 break;
72 77 case D_T_FMT:
73 78 ret = (char *)TIME->c_fmt;
74 79 break;
75 80 case D_FMT:
76 81 ret = (char *)TIME->x_fmt;
77 82 break;
78 83 case T_FMT:
79 84 ret = (char *)TIME->X_fmt;
80 85 break;
81 86 case T_FMT_AMPM:
82 87 ret = (char *)TIME->ampm_fmt;
83 88 break;
84 89 case AM_STR:
85 90 ret = (char *)TIME->am;
86 91 break;
87 92 case PM_STR:
88 93 ret = (char *)TIME->pm;
89 94 break;
90 95 case DAY_1: case DAY_2: case DAY_3:
91 96 case DAY_4: case DAY_5: case DAY_6: case DAY_7:
92 97 ret = (char *)TIME->weekday[_REL(DAY_1)];
93 98 break;
94 99 case ABDAY_1: case ABDAY_2: case ABDAY_3:
95 100 case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7:
96 101 ret = (char *)TIME->wday[_REL(ABDAY_1)];
97 102 break;
98 103 case MON_1: case MON_2: case MON_3: case MON_4:
99 104 case MON_5: case MON_6: case MON_7: case MON_8:
100 105 case MON_9: case MON_10: case MON_11: case MON_12:
101 106 ret = (char *)TIME->month[_REL(MON_1)];
102 107 break;
103 108 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4:
104 109 case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8:
105 110 case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12:
106 111 ret = (char *)TIME->mon[_REL(ABMON_1)];
107 112 break;
108 113 case ERA:
109 114 /* XXX: need to be implemented */
110 115 ret = "";
111 116 break;
112 117 case ERA_D_FMT:
113 118 /* XXX: need to be implemented */
114 119 ret = "";
115 120 break;
116 121 case ERA_D_T_FMT:
117 122 /* XXX: need to be implemented */
118 123 ret = "";
119 124 break;
120 125 case ERA_T_FMT:
121 126 /* XXX: need to be implemented */
122 127 ret = "";
123 128 break;
124 129 case ALT_DIGITS:
125 130 /* XXX: need to be implemented */
126 131 ret = "";
127 132 break;
128 133 case RADIXCHAR:
129 134 ret = (char *)NUMERIC->decimal_point;
130 135 break;
131 136 case THOUSEP:
132 137 ret = (char *)NUMERIC->thousands_sep;
133 138 break;
134 139 case YESEXPR:
135 140 ret = (char *)MESSAGES->yesexpr;
136 141 break;
137 142 case NOEXPR:
138 143 ret = (char *)MESSAGES->noexpr;
139 144 break;
140 145 /*
141 146 * YESSTR and NOSTR items marked with LEGACY are available, but not
142 147 * recomended by SUSv2 to be used in portable applications since
143 148 * they're subject to remove in future specification editions.
144 149 */
145 150 case YESSTR: /* LEGACY */
146 151 ret = (char *)MESSAGES->yesstr;
147 152 break;
148 153 case NOSTR: /* LEGACY */
149 154 ret = (char *)MESSAGES->nostr;
150 155 break;
151 156 /*
152 157 * SUSv2 special formatted currency string
153 158 */
154 159 case CRNCYSTR:
155 160 ret = "";
156 161 cs = (char *)MONETARY->currency_symbol;
157 162 if (*cs != '\0') {
158 163 char pos = localeconv()->p_cs_precedes;
159 164
160 165 if (pos == localeconv()->n_cs_precedes) {
161 166 char psn = '\0';
162 167
163 168 if (pos == CHAR_MAX) {
164 169 if (strcmp(cs,
165 170 MONETARY->mon_decimal_point) == 0)
166 171 psn = '.';
167 172 } else
168 173 psn = pos ? '-' : '+';
169 174 if (psn != '\0') {
170 175 int clen = strlen(cs);
171 176 char *newc;
172 177
173 178 newc = realloc(csym, clen + 2);
174 179 if (newc != NULL) {
175 180 free(csym);
176 181 csym = newc;
177 182 *csym = psn;
178 183 (void) strcpy(csym + 1, cs);
179 184 ret = csym;
180 185 }
181 186 }
182 187 }
183 188 }
184 189 break;
185 190 case _DATE_FMT: /* Solaris specific extension */
186 191 ret = (char *)TIME->date_fmt;
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
187 192 break;
188 193 /*
189 194 * Note that FreeBSD also had a private D_MD_ORDER, but that appears
190 195 * to have been specific to FreeBSD, so we have not included it here.
191 196 */
192 197 default:
193 198 ret = "";
194 199 }
195 200 return (ret);
196 201 }
202 +
203 +char *
204 +nl_langinfo(nl_item item)
205 +{
206 + return (nl_langinfo_l(item, __get_locale()));
207 +}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX