1 /*
2 Copyright (c) 1996 - 2002 FreeBSD Project
3 Copyright (c) 1991, 1993
4 The Regents of the University of California. All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 4. Neither the name of the University nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 SUCH DAMAGE.
29 */
30 #include "newlib.h"
31 #include "setlocale.h"
32
33 struct lconv *
__localeconv_l(struct __locale_t * locale)34 __localeconv_l (struct __locale_t *locale)
35 {
36 struct lconv *lconv = &locale->lconv;
37 if (locale == __get_C_locale ())
38 return lconv;
39
40 #ifdef __HAVE_LOCALE_INFO__
41 const struct lc_numeric_T *n = __get_numeric_locale (locale);
42 const struct lc_monetary_T *m = __get_monetary_locale (locale);
43
44 lconv->decimal_point = (char *) n->decimal_point;
45 lconv->thousands_sep = (char *) n->thousands_sep;
46 lconv->grouping = (char *) n->grouping;
47 lconv->int_curr_symbol = (char *) m->int_curr_symbol;
48 lconv->currency_symbol = (char *) m->currency_symbol;
49 lconv->mon_decimal_point = (char *) m->mon_decimal_point;
50 lconv->mon_thousands_sep = (char *) m->mon_thousands_sep;
51 lconv->mon_grouping = (char *) m->mon_grouping;
52 lconv->positive_sign = (char *) m->positive_sign;
53 lconv->negative_sign = (char *) m->negative_sign;
54 lconv->int_frac_digits = m->int_frac_digits[0];
55 lconv->frac_digits = m->frac_digits[0];
56 lconv->p_cs_precedes = m->p_cs_precedes[0];
57 lconv->p_sep_by_space = m->p_sep_by_space[0];
58 lconv->n_cs_precedes = m->n_cs_precedes[0];
59 lconv->n_sep_by_space = m->n_sep_by_space[0];
60 lconv->p_sign_posn = m->p_sign_posn[0];
61 lconv->n_sign_posn = m->n_sign_posn[0];
62 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
63 lconv->int_p_cs_precedes = m->int_p_cs_precedes[0];
64 lconv->int_p_sep_by_space = m->int_p_sep_by_space[0];
65 lconv->int_n_cs_precedes = m->int_n_cs_precedes[0];
66 lconv->int_n_sep_by_space = m->int_n_sep_by_space[0];
67 lconv->int_n_sign_posn = m->int_n_sign_posn[0];
68 lconv->int_p_sign_posn = m->int_p_sign_posn[0];
69 #else /* !__HAVE_LOCALE_INFO_EXTENDED__ */
70 lconv->int_p_cs_precedes = m->p_cs_precedes[0];
71 lconv->int_p_sep_by_space = m->p_sep_by_space[0];
72 lconv->int_n_cs_precedes = m->n_cs_precedes[0];
73 lconv->int_n_sep_by_space = m->n_sep_by_space[0];
74 lconv->int_n_sign_posn = m->n_sign_posn[0];
75 lconv->int_p_sign_posn = m->p_sign_posn[0];
76 #endif /* !__HAVE_LOCALE_INFO_EXTENDED__ */
77 #endif /* __HAVE_LOCALE_INFO__ */
78 return lconv;
79 }
80
81 struct lconv *
localeconv(void)82 localeconv (void)
83 {
84 /* Note that we always fall back to the global locale, even in case
85 of specifying a reent. Otherwise a call to _localeconv_r would just
86 crash if the reent locale pointer is NULL. */
87 return __localeconv_l (__get_current_locale ());
88 }
89