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