xref: /netbsd/lib/libc/locale/localeconv.c (revision bf9ec67e)
1 /*	$NetBSD: localeconv.c,v 1.10 2001/01/02 10:53:25 kleink Exp $	*/
2 
3 /*
4  * Written by J.T. Conklin <jtc@netbsd.org>.
5  * Public domain.
6  */
7 
8 #include <sys/cdefs.h>
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: localeconv.c,v 1.10 2001/01/02 10:53:25 kleink Exp $");
11 #endif /* LIBC_SCCS and not lint */
12 
13 #include <sys/localedef.h>
14 #include <locale.h>
15 
16 /*
17  * The localeconv() function constructs a struct lconv from the current
18  * monetary and numeric locales.
19  *
20  * Because localeconv() may be called many times (especially by library
21  * routines like printf() & strtod()), the approprate members of the
22  * lconv structure are computed only when the monetary or numeric
23  * locale has been changed.
24  */
25 int __mlocale_changed = 1;
26 int __nlocale_changed = 1;
27 
28 /*
29  * Return the current locale conversion.
30  */
31 struct lconv *
32 localeconv()
33 {
34     static struct lconv ret;
35 
36     if (__mlocale_changed) {
37 	/* LC_MONETARY */
38 	ret.int_curr_symbol	= _CurrentMonetaryLocale->int_curr_symbol;
39 	ret.currency_symbol	= _CurrentMonetaryLocale->currency_symbol;
40 	ret.mon_decimal_point	= _CurrentMonetaryLocale->mon_decimal_point;
41 	ret.mon_thousands_sep	= _CurrentMonetaryLocale->mon_thousands_sep;
42 	ret.mon_grouping	= _CurrentMonetaryLocale->mon_grouping;
43 	ret.positive_sign	= _CurrentMonetaryLocale->positive_sign;
44 	ret.negative_sign	= _CurrentMonetaryLocale->negative_sign;
45 	ret.int_frac_digits	= _CurrentMonetaryLocale->int_frac_digits;
46 	ret.frac_digits		= _CurrentMonetaryLocale->frac_digits;
47 	ret.p_cs_precedes	= _CurrentMonetaryLocale->p_cs_precedes;
48 	ret.p_sep_by_space	= _CurrentMonetaryLocale->p_sep_by_space;
49 	ret.n_cs_precedes	= _CurrentMonetaryLocale->n_cs_precedes;
50 	ret.n_sep_by_space	= _CurrentMonetaryLocale->n_sep_by_space;
51 	ret.p_sign_posn		= _CurrentMonetaryLocale->p_sign_posn;
52 	ret.n_sign_posn		= _CurrentMonetaryLocale->n_sign_posn;
53 	ret.int_p_cs_precedes	= _CurrentMonetaryLocale->int_p_cs_precedes;
54 	ret.int_n_cs_precedes	= _CurrentMonetaryLocale->int_n_cs_precedes;
55 	ret.int_p_sep_by_space	= _CurrentMonetaryLocale->int_p_sep_by_space;
56 	ret.int_n_sep_by_space	= _CurrentMonetaryLocale->int_n_sep_by_space;
57 	ret.int_p_sign_posn	= _CurrentMonetaryLocale->int_p_sign_posn;
58 	ret.int_n_sign_posn	= _CurrentMonetaryLocale->int_n_sign_posn;
59 	__mlocale_changed = 0;
60     }
61 
62     if (__nlocale_changed) {
63 	/* LC_NUMERIC */
64 	/* LINTED const castaway */
65 	ret.decimal_point	= (char *) _CurrentNumericLocale->decimal_point;
66 	/* LINTED const castaway */
67 	ret.thousands_sep	= (char *) _CurrentNumericLocale->thousands_sep;
68 	/* LINTED const castaway */
69 	ret.grouping		= (char *) _CurrentNumericLocale->grouping;
70 	__nlocale_changed = 0;
71     }
72 
73     return (&ret);
74 }
75