xref: /dragonfly/lib/libc/locale/localeconv.c (revision b7367ef6)
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 $ */
3 
4 /*
5  * Written by J.T. Conklin <jtc@NetBSD.org>.
6  * Public domain.
7  */
8 
9 #include <sys/localedef.h>
10 #include <locale.h>
11 
12 /*
13  * The localeconv() function constructs a struct lconv from the current
14  * monetary and numeric locales.
15  *
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.
20  */
21 int __mlocale_changed = 1;
22 int __nlocale_changed = 1;
23 
24 /*
25  * Return the current locale conversion.
26  */
27 struct lconv *
28 localeconv(void)
29 {
30 	static struct lconv ret;
31 
32 	if (__mlocale_changed) {
33 		/* LC_MONETARY */
34 		ret.int_curr_symbol =
35 		    (char *)_CurrentMonetaryLocale->int_curr_symbol;
36 		ret.currency_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;
42 		ret.mon_grouping =
43 		    (char *)_CurrentMonetaryLocale->mon_grouping;
44 		ret.positive_sign =
45 		    (char *)_CurrentMonetaryLocale->positive_sign;
46 		ret.negative_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;
67 	}
68 
69 	if (__nlocale_changed) {
70 		/* LC_NUMERIC */
71 		ret.decimal_point =
72 		    (char *)_CurrentNumericLocale->decimal_point;
73 		ret.thousands_sep =
74 		    (char *)_CurrentNumericLocale->thousands_sep;
75 		ret.grouping =
76 		    (char *)_CurrentNumericLocale->grouping;
77 		__nlocale_changed = 0;
78 	}
79 
80 	return(&ret);
81 }
82