1 /* $NetBSD: src/lib/libc/locale/localeconv.c,v 1.12 2004/01/02 21:53:49 itojun Exp $ */
2 /* $DragonFly: src/lib/libc/locale/localeconv.c,v 1.4 2007/09/20 07:40:51 hasso Exp $ */
5 * Written by J.T. Conklin <jtc@NetBSD.org>.
9 #include <sys/localedef.h>
13 * The localeconv() function constructs a struct lconv from the current
14 * monetary and numeric locales.
16 * Because localeconv() may be called many times (especially by library
17 * routines like printf() & strtod()), the appropriate members of the
18 * lconv structure are computed only when the monetary or numeric
19 * locale has been changed.
21 int __mlocale_changed = 1;
22 int __nlocale_changed = 1;
25 * Return the current locale conversion.
30 static struct lconv ret;
32 if (__mlocale_changed) {
35 (char *)_CurrentMonetaryLocale->int_curr_symbol;
37 (char *)_CurrentMonetaryLocale->currency_symbol;
38 ret.mon_decimal_point =
39 (char *)_CurrentMonetaryLocale->mon_decimal_point;
40 ret.mon_thousands_sep =
41 (char *)_CurrentMonetaryLocale->mon_thousands_sep;
43 (char *)_CurrentMonetaryLocale->mon_grouping;
45 (char *)_CurrentMonetaryLocale->positive_sign;
47 (char *)_CurrentMonetaryLocale->negative_sign;
48 ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
49 ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
50 ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
51 ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
52 ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
53 ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
54 ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
55 ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
56 ret.int_p_cs_precedes =
57 _CurrentMonetaryLocale->int_p_cs_precedes;
58 ret.int_n_cs_precedes =
59 _CurrentMonetaryLocale->int_n_cs_precedes;
60 ret.int_p_sep_by_space =
61 _CurrentMonetaryLocale->int_p_sep_by_space;
62 ret.int_n_sep_by_space =
63 _CurrentMonetaryLocale->int_n_sep_by_space;
64 ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;
65 ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;
66 __mlocale_changed = 0;
69 if (__nlocale_changed) {
72 (char *)_CurrentNumericLocale->decimal_point;
74 (char *)_CurrentNumericLocale->thousands_sep;
76 (char *)_CurrentNumericLocale->grouping;
77 __nlocale_changed = 0;