1 1.14 tnozaki /* $NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $ */ 2 1.7 kleink 3 1.1 cgd /* 4 1.11 salo * Written by J.T. Conklin <jtc (at) NetBSD.org>. 5 1.6 jtc * Public domain. 6 1.1 cgd */ 7 1.1 cgd 8 1.8 christos #include <sys/cdefs.h> 9 1.1 cgd #if defined(LIBC_SCCS) && !defined(lint) 10 1.14 tnozaki __RCSID("$NetBSD: localeconv.c,v 1.14 2007/05/26 13:14:13 tnozaki Exp $"); 11 1.1 cgd #endif /* LIBC_SCCS and not lint */ 12 1.1 cgd 13 1.5 jtc #include <sys/localedef.h> 14 1.1 cgd #include <locale.h> 15 1.1 cgd 16 1.4 jtc /* 17 1.4 jtc * The localeconv() function constructs a struct lconv from the current 18 1.4 jtc * monetary and numeric locales. 19 1.4 jtc * 20 1.4 jtc * Because localeconv() may be called many times (especially by library 21 1.14 tnozaki * routines like printf() & strtod()), the appropriate members of the 22 1.4 jtc * lconv structure are computed only when the monetary or numeric 23 1.4 jtc * locale has been changed. 24 1.4 jtc */ 25 1.4 jtc int __mlocale_changed = 1; 26 1.4 jtc int __nlocale_changed = 1; 27 1.4 jtc 28 1.1 cgd /* 29 1.1 cgd * Return the current locale conversion. 30 1.1 cgd */ 31 1.1 cgd struct lconv * 32 1.1 cgd localeconv() 33 1.1 cgd { 34 1.12 itojun static struct lconv ret; 35 1.4 jtc 36 1.12 itojun if (__mlocale_changed) { 37 1.12 itojun /* LC_MONETARY */ 38 1.13 christos ret.int_curr_symbol = 39 1.13 christos __UNCONST(_CurrentMonetaryLocale->int_curr_symbol); 40 1.13 christos ret.currency_symbol = 41 1.13 christos __UNCONST(_CurrentMonetaryLocale->currency_symbol); 42 1.12 itojun ret.mon_decimal_point = 43 1.13 christos __UNCONST(_CurrentMonetaryLocale->mon_decimal_point); 44 1.12 itojun ret.mon_thousands_sep = 45 1.13 christos __UNCONST(_CurrentMonetaryLocale->mon_thousands_sep); 46 1.13 christos ret.mon_grouping = 47 1.13 christos __UNCONST(_CurrentMonetaryLocale->mon_grouping); 48 1.13 christos ret.positive_sign = 49 1.13 christos __UNCONST(_CurrentMonetaryLocale->positive_sign); 50 1.13 christos ret.negative_sign = 51 1.13 christos __UNCONST(_CurrentMonetaryLocale->negative_sign); 52 1.12 itojun ret.int_frac_digits = _CurrentMonetaryLocale->int_frac_digits; 53 1.12 itojun ret.frac_digits = _CurrentMonetaryLocale->frac_digits; 54 1.12 itojun ret.p_cs_precedes = _CurrentMonetaryLocale->p_cs_precedes; 55 1.12 itojun ret.p_sep_by_space = _CurrentMonetaryLocale->p_sep_by_space; 56 1.12 itojun ret.n_cs_precedes = _CurrentMonetaryLocale->n_cs_precedes; 57 1.12 itojun ret.n_sep_by_space = _CurrentMonetaryLocale->n_sep_by_space; 58 1.12 itojun ret.p_sign_posn = _CurrentMonetaryLocale->p_sign_posn; 59 1.12 itojun ret.n_sign_posn = _CurrentMonetaryLocale->n_sign_posn; 60 1.12 itojun ret.int_p_cs_precedes = 61 1.12 itojun _CurrentMonetaryLocale->int_p_cs_precedes; 62 1.12 itojun ret.int_n_cs_precedes = 63 1.12 itojun _CurrentMonetaryLocale->int_n_cs_precedes; 64 1.12 itojun ret.int_p_sep_by_space = 65 1.12 itojun _CurrentMonetaryLocale->int_p_sep_by_space; 66 1.12 itojun ret.int_n_sep_by_space = 67 1.12 itojun _CurrentMonetaryLocale->int_n_sep_by_space; 68 1.12 itojun ret.int_p_sign_posn = _CurrentMonetaryLocale->int_p_sign_posn; 69 1.12 itojun ret.int_n_sign_posn = _CurrentMonetaryLocale->int_n_sign_posn; 70 1.12 itojun __mlocale_changed = 0; 71 1.12 itojun } 72 1.12 itojun 73 1.12 itojun if (__nlocale_changed) { 74 1.12 itojun /* LC_NUMERIC */ 75 1.12 itojun ret.decimal_point = 76 1.13 christos __UNCONST(_CurrentNumericLocale->decimal_point); 77 1.12 itojun ret.thousands_sep = 78 1.13 christos __UNCONST(_CurrentNumericLocale->thousands_sep); 79 1.13 christos ret.grouping = 80 1.13 christos __UNCONST(_CurrentNumericLocale->grouping); 81 1.12 itojun __nlocale_changed = 0; 82 1.12 itojun } 83 1.1 cgd 84 1.12 itojun return (&ret); 85 1.1 cgd } 86