Home | History | Annotate | Line # | Download | only in locale
localeconv.c revision 1.9
      1 /*	$NetBSD: localeconv.c,v 1.9 1998/11/13 15:49:03 christos Exp $	*/
      2 
      3 /*
      4  * Written by J.T. Conklin <jtc (at) 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.9 1998/11/13 15:49:03 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	= _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 	__mlocale_changed = 0;
     54     }
     55 
     56     if (__nlocale_changed) {
     57 	/* LC_NUMERIC */
     58 	/* LINTED const castaway */
     59 	ret.decimal_point	= (char *) _CurrentNumericLocale->decimal_point;
     60 	/* LINTED const castaway */
     61 	ret.thousands_sep	= (char *) _CurrentNumericLocale->thousands_sep;
     62 	/* LINTED const castaway */
     63 	ret.grouping		= (char *) _CurrentNumericLocale->grouping;
     64 	__nlocale_changed = 0;
     65     }
     66 
     67     return (&ret);
     68 }
     69