NetBSD/lib/libc/locale/localeconv.c

86 lines
2.7 KiB
C
Raw Normal View History

2007-05-26 17:14:13 +04:00
/* $NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $ */
1997-04-29 20:40:13 +04:00
1993-03-21 12:45:37 +03:00
/*
2003-07-26 23:24:24 +04:00
* Written by J.T. Conklin <jtc@NetBSD.org>.
* Public domain.
1993-03-21 12:45:37 +03:00
*/
1997-07-13 23:54:55 +04:00
#include <sys/cdefs.h>
1993-03-21 12:45:37 +03:00
#if defined(LIBC_SCCS) && !defined(lint)
2007-05-26 17:14:13 +04:00
__RCSID("$NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $");
1993-03-21 12:45:37 +03:00
#endif /* LIBC_SCCS and not lint */
#include <sys/localedef.h>
1993-03-21 12:45:37 +03:00
#include <locale.h>
/*
* The localeconv() function constructs a struct lconv from the current
* monetary and numeric locales.
*
* Because localeconv() may be called many times (especially by library
2007-05-26 17:14:13 +04:00
* routines like printf() & strtod()), the appropriate members of the
* lconv structure are computed only when the monetary or numeric
* locale has been changed.
*/
int __mlocale_changed = 1;
int __nlocale_changed = 1;
1993-03-21 12:45:37 +03:00
/*
* Return the current locale conversion.
*/
struct lconv *
localeconv()
{
2004-01-03 00:49:35 +03:00
static struct lconv ret;
2004-01-03 00:49:35 +03:00
if (__mlocale_changed) {
/* LC_MONETARY */
2005-11-29 06:11:58 +03:00
ret.int_curr_symbol =
__UNCONST(_CurrentMonetaryLocale->int_curr_symbol);
ret.currency_symbol =
__UNCONST(_CurrentMonetaryLocale->currency_symbol);
2004-01-03 00:49:35 +03:00
ret.mon_decimal_point =
2005-11-29 06:11:58 +03:00
__UNCONST(_CurrentMonetaryLocale->mon_decimal_point);
2004-01-03 00:49:35 +03:00
ret.mon_thousands_sep =
2005-11-29 06:11:58 +03:00
__UNCONST(_CurrentMonetaryLocale->mon_thousands_sep);
ret.mon_grouping =
__UNCONST(_CurrentMonetaryLocale->mon_grouping);
ret.positive_sign =
__UNCONST(_CurrentMonetaryLocale->positive_sign);
ret.negative_sign =
__UNCONST(_CurrentMonetaryLocale->negative_sign);
2004-01-03 00:49:35 +03:00
ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits;
ret.frac_digits = _CurrentMonetaryLocale->frac_digits;
ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes;
ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space;
ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes;
ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space;
ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn;
ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn;
ret.int_p_cs_precedes =
_CurrentMonetaryLocale->int_p_cs_precedes;
ret.int_n_cs_precedes =
_CurrentMonetaryLocale->int_n_cs_precedes;
ret.int_p_sep_by_space =
_CurrentMonetaryLocale->int_p_sep_by_space;
ret.int_n_sep_by_space =
_CurrentMonetaryLocale->int_n_sep_by_space;
ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn;
ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn;
__mlocale_changed = 0;
}
2004-01-03 00:49:35 +03:00
if (__nlocale_changed) {
/* LC_NUMERIC */
ret.decimal_point =
2005-11-29 06:11:58 +03:00
__UNCONST(_CurrentNumericLocale->decimal_point);
2004-01-03 00:49:35 +03:00
ret.thousands_sep =
2005-11-29 06:11:58 +03:00
__UNCONST(_CurrentNumericLocale->thousands_sep);
ret.grouping =
__UNCONST(_CurrentNumericLocale->grouping);
2004-01-03 00:49:35 +03:00
__nlocale_changed = 0;
}
1993-03-21 12:45:37 +03:00
2004-01-03 00:49:35 +03:00
return (&ret);
1993-03-21 12:45:37 +03:00
}