1 --- strfmon.c.orig 2008-04-04 21:54:54.000000000 -0700
2 +++ strfmon.c 2008-04-04 22:11:39.000000000 -0700
3 @@ -41,6 +41,8 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0
7 +#include "xlocale_private.h"
12 @@ -75,9 +77,9 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0
14 } while (/* CONSTCOND */ 0)
16 -#define GET_NUMBER(VAR) do { \
17 +#define GET_NUMBER(VAR,LOC) do { \
19 - while (isdigit((unsigned char)*fmt)) { \
20 + while (isdigit_l((unsigned char)*fmt, (LOC))) { \
23 if (VAR > 0x00ffffff) \
24 @@ -99,15 +101,13 @@ __RCSID("$NetBSD: strfmon.c,v 1.6 2008/0
26 } while (/* CONSTCOND */ 0)
28 -static void __setup_vars(int, char *, char *, char *, const char **);
29 -static int __calc_left_pad(int, char *);
30 -static char *__format_grouped_double(double, int *, int, int, int);
31 +static void __setup_vars(int, char *, char *, char *, const char **, struct lconv *);
32 +static int __calc_left_pad(int, char *, struct lconv *);
33 +static char *__format_grouped_double(double, int *, int, int, int, struct lconv *, locale_t);
36 -strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
39 +_strfmon(char * __restrict s, size_t maxsize, locale_t loc, const char * __restrict format, va_list ap)
42 char *dst; /* output destination pointer */
43 const char *fmt; /* current format poistion pointer */
44 struct lconv *lc; /* pointer to lconv structure */
45 @@ -131,9 +131,7 @@ strfmon(char * __restrict s, size_t maxs
46 char *tmpptr; /* temporary vars */
49 - va_start(ap, format);
52 + lc = localeconv_l(loc);
56 @@ -197,9 +195,9 @@ strfmon(char * __restrict s, size_t maxs
60 - if (isdigit((unsigned char)*fmt)) {
61 + if (isdigit_l((unsigned char)*fmt, loc)) {
62 ptrdiff_t d = dst - s;
64 + GET_NUMBER(width, loc);
65 /* Do we have enough space to put number with
68 @@ -210,16 +208,16 @@ strfmon(char * __restrict s, size_t maxs
72 - if (!isdigit((unsigned char)*++fmt))
73 + if (!isdigit_l((unsigned char)*++fmt, loc))
75 - GET_NUMBER(left_prec);
76 + GET_NUMBER(left_prec, loc);
81 - if (!isdigit((unsigned char)*++fmt))
82 + if (!isdigit_l((unsigned char)*++fmt, loc))
84 - GET_NUMBER(right_prec);
85 + GET_NUMBER(right_prec, loc);
88 /* Conversion Characters */
89 @@ -239,8 +237,10 @@ strfmon(char * __restrict s, size_t maxs
90 free(currency_symbol);
91 if (flags & USE_INTL_CURRENCY) {
92 currency_symbol = strdup(lc->int_curr_symbol);
93 - if (currency_symbol != NULL)
94 + if (currency_symbol != NULL) {
95 space_char = *(currency_symbol+3);
96 + currency_symbol[3] = '\0';
99 currency_symbol = strdup(lc->currency_symbol);
101 @@ -259,21 +259,21 @@ strfmon(char * __restrict s, size_t maxs
102 /* fill left_prec with amount of padding chars */
103 if (left_prec >= 0) {
104 pad_size = __calc_left_pad((flags ^ IS_NEGATIVE),
106 - __calc_left_pad(flags, currency_symbol);
107 + currency_symbol, lc) -
108 + __calc_left_pad(flags, currency_symbol, lc);
113 asciivalue = __format_grouped_double(value, &flags,
114 - left_prec, right_prec, pad_char);
115 + left_prec, right_prec, pad_char, lc, loc);
116 if (asciivalue == NULL)
117 goto end_error; /* errno already set */
118 /* to ENOMEM by malloc() */
120 /* set some variables for later use */
121 __setup_vars(flags, &cs_precedes, &sep_by_space,
122 - &sign_posn, &signstr);
123 + &sign_posn, &signstr, lc);
126 * Description of some LC_MONETARY's values:
127 @@ -333,8 +333,11 @@ strfmon(char * __restrict s, size_t maxs
128 } else if (sep_by_space == 1)
131 - } else if (sign_posn == 1)
132 + } else if (sign_posn == 1) {
134 + if (sep_by_space == 2)
140 @@ -368,8 +371,12 @@ strfmon(char * __restrict s, size_t maxs
144 - if (sign_posn == 0 && (flags & IS_NEGATIVE))
146 + if (sign_posn == 0) {
147 + if (flags & IS_NEGATIVE)
149 + else if (left_prec >= 0)
153 if (dst - tmpptr < width) {
154 if (flags & LEFT_JUSTIFY) {
155 @@ -386,7 +393,6 @@ strfmon(char * __restrict s, size_t maxs
161 free(currency_symbol);
162 return (dst - s - 1); /* return size of put data except trailing '\0' */
163 @@ -405,14 +411,12 @@ end_error:
164 if (currency_symbol != NULL)
165 free(currency_symbol);
172 __setup_vars(int flags, char *cs_precedes, char *sep_by_space,
173 - char *sign_posn, const char **signstr) {
174 - struct lconv *lc = localeconv();
175 + char *sign_posn, const char **signstr, struct lconv *lc) {
177 if ((flags & IS_NEGATIVE) && (flags & USE_INTL_CURRENCY)) {
178 *cs_precedes = lc->int_n_cs_precedes;
179 @@ -448,13 +452,13 @@ __setup_vars(int flags, char *cs_precede
183 -__calc_left_pad(int flags, char *cur_symb) {
184 +__calc_left_pad(int flags, char *cur_symb, struct lconv *lc) {
186 char cs_precedes, sep_by_space, sign_posn;
190 - __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr);
191 + __setup_vars(flags, &cs_precedes, &sep_by_space, &sign_posn, &signstr, lc);
193 if (cs_precedes != 0) {
194 left_chars += strlen(cur_symb);
195 @@ -463,6 +467,10 @@ __calc_left_pad(int flags, char *cur_sym
200 + if (flags & IS_NEGATIVE)
204 left_chars += strlen(signstr);
206 @@ -498,9 +506,11 @@ get_groups(int size, char *grouping) {
209 /* convert double to ASCII */
210 +__private_extern__ const char *__fix_nogrouping(const char *);
213 __format_grouped_double(double value, int *flags,
214 - int left_prec, int right_prec, int pad_char) {
215 + int left_prec, int right_prec, int pad_char, struct lconv *lc, locale_t loc) {
219 @@ -512,14 +522,13 @@ __format_grouped_double(double value, in
223 - struct lconv *lc = localeconv();
230 - grouping = lc->mon_grouping;
231 + grouping = __fix_nogrouping(lc->mon_grouping);
232 decimal_point = *lc->mon_decimal_point;
233 if (decimal_point == '\0')
234 decimal_point = *lc->decimal_point;
235 @@ -546,9 +555,9 @@ __format_grouped_double(double value, in
236 left_prec += get_groups(left_prec, grouping);
238 /* convert to string */
239 - snprintf(fmt, sizeof(fmt), "%%%d.%df", left_prec + right_prec + 1,
240 + snprintf_l(fmt, sizeof(fmt), loc, "%%%d.%df", left_prec + right_prec + 1,
242 - avalue_size = asprintf(&avalue, fmt, value);
243 + avalue_size = asprintf_l(&avalue, loc, fmt, value);
247 @@ -621,3 +630,30 @@ __format_grouped_double(double value, in
253 +strfmon(char * __restrict s, size_t maxsize, const char * __restrict format,
259 + va_start(ap, format);
260 + ret = _strfmon(s, maxsize, __current_locale(), format, ap);
266 +strfmon_l(char * __restrict s, size_t maxsize, locale_t loc,
267 + const char * __restrict format, ...)
272 + NORMALIZE_LOCALE(loc);
273 + va_start(ap, format);
274 + ret = _strfmon(s, maxsize, loc, format, ap);