1 /* $NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos Exp $ */ 2 3 /* 4 * Written by J.T. Conklin <jtc (at) NetBSD.org>. 5 * Public domain. 6 */ 7 #include <LibConfig.h> 8 #include <sys/EfiCdefs.h> 9 #if defined(LIBC_SCCS) && !defined(lint) 10 __RCSID("$NetBSD: localeconv.c,v 1.13 2005/11/29 03:11:59 christos 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 = 39 __UNCONST(_CurrentMonetaryLocale->int_curr_symbol); 40 ret.currency_symbol = 41 __UNCONST(_CurrentMonetaryLocale->currency_symbol); 42 ret.mon_decimal_point = 43 __UNCONST(_CurrentMonetaryLocale->mon_decimal_point); 44 ret.mon_thousands_sep = 45 __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep); 46 ret.mon_grouping = 47 __UNCONST(_CurrentMonetaryLocale->mon_grouping); 48 ret.positive_sign = 49 __UNCONST(_CurrentMonetaryLocale->positive_sign); 50 ret.negative_sign = 51 __UNCONST(_CurrentMonetaryLocale->negative_sign); 52 ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits; 53 ret.frac_digits = _CurrentMonetaryLocale->frac_digits; 54 ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes; 55 ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space; 56 ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes; 57 ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space; 58 ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn; 59 ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn; 60 ret.int_p_cs_precedes = 61 _CurrentMonetaryLocale->int_p_cs_precedes; 62 ret.int_n_cs_precedes = 63 _CurrentMonetaryLocale->int_n_cs_precedes; 64 ret.int_p_sep_by_space = 65 _CurrentMonetaryLocale->int_p_sep_by_space; 66 ret.int_n_sep_by_space = 67 _CurrentMonetaryLocale->int_n_sep_by_space; 68 ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn; 69 ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn; 70 __mlocale_changed = 0; 71 } 72 73 if (__nlocale_changed) { 74 /* LC_NUMERIC */ 75 ret.decimal_point = 76 __UNCONST(_CurrentNumericLocale->decimal_point); 77 ret.thousands_sep = 78 __UNCONST(_CurrentNumericLocale->thousands_sep); 79 ret.grouping = 80 __UNCONST(_CurrentNumericLocale->grouping); 81 __nlocale_changed = 0; 82 } 83 84 return (&ret); 85 } 86