11573Srgrimes/* 288278Sphantom * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> 31573Srgrimes * Copyright (c) 1991, 1993 41573Srgrimes * The Regents of the University of California. All rights reserved. 51573Srgrimes * 6227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation 7227753Stheraven * All rights reserved. 8227753Stheraven * Portions of this software were developed by David Chisnall 9227753Stheraven * under sponsorship from the FreeBSD Foundation. 10227753Stheraven * 111573Srgrimes * Redistribution and use in source and binary forms, with or without 121573Srgrimes * modification, are permitted provided that the following conditions 131573Srgrimes * are met: 141573Srgrimes * 1. Redistributions of source code must retain the above copyright 151573Srgrimes * notice, this list of conditions and the following disclaimer. 161573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 171573Srgrimes * notice, this list of conditions and the following disclaimer in the 181573Srgrimes * documentation and/or other materials provided with the distribution. 1973654Sobrien * 4. Neither the name of the University nor the names of its contributors 2073654Sobrien * may be used to endorse or promote products derived from this software 2173654Sobrien * without specific prior written permission. 221573Srgrimes * 231573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331573Srgrimes * SUCH DAMAGE. 341573Srgrimes */ 351573Srgrimes 361573Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 371573Srgrimesstatic char sccsid[] = "@(#)localeconv.c 8.1 (Berkeley) 6/4/93"; 381573Srgrimes#endif /* LIBC_SCCS and not lint */ 3992986Sobrien#include <sys/cdefs.h> 4092986Sobrien__FBSDID("$FreeBSD: releng/10.3/lib/libc/locale/localeconv.c 227753 2011-11-20 14:45:42Z theraven $"); 411573Srgrimes 421573Srgrimes#include <locale.h> 43116875Sphantom 4472166Sphantom#include "lmonetary.h" 4572166Sphantom#include "lnumeric.h" 461573Srgrimes 4772166Sphantom/* 4872166Sphantom * The localeconv() function constructs a struct lconv from the current 4972166Sphantom * monetary and numeric locales. 5072166Sphantom * 5172166Sphantom * Because localeconv() may be called many times (especially by library 5272166Sphantom * routines like printf() & strtod()), the approprate members of the 5372166Sphantom * lconv structure are computed only when the monetary or numeric 5472166Sphantom * locale has been changed. 5572166Sphantom */ 5672166Sphantom 571573Srgrimes/* 581573Srgrimes * Return the current locale conversion. 591573Srgrimes */ 601573Srgrimesstruct lconv * 61227753Stheravenlocaleconv_l(locale_t loc) 621573Srgrimes{ 63227753Stheraven FIX_LOCALE(loc); 64227753Stheraven struct lconv *ret = &loc->lconv; 651573Srgrimes 66227753Stheraven if (loc->monetary_locale_changed) { 6772166Sphantom /* LC_MONETARY part */ 6872166Sphantom struct lc_monetary_T * mptr; 6972166Sphantom 70227753Stheraven#define M_ASSIGN_STR(NAME) (ret->NAME = (char*)mptr->NAME) 71227753Stheraven#define M_ASSIGN_CHAR(NAME) (ret->NAME = mptr->NAME[0]) 7272166Sphantom 73227753Stheraven mptr = __get_current_monetary_locale(loc); 7472166Sphantom M_ASSIGN_STR(int_curr_symbol); 7572166Sphantom M_ASSIGN_STR(currency_symbol); 7672166Sphantom M_ASSIGN_STR(mon_decimal_point); 7772166Sphantom M_ASSIGN_STR(mon_thousands_sep); 7872321Sphantom M_ASSIGN_STR(mon_grouping); 7972166Sphantom M_ASSIGN_STR(positive_sign); 8072166Sphantom M_ASSIGN_STR(negative_sign); 8172166Sphantom M_ASSIGN_CHAR(int_frac_digits); 8272166Sphantom M_ASSIGN_CHAR(frac_digits); 8372166Sphantom M_ASSIGN_CHAR(p_cs_precedes); 8472166Sphantom M_ASSIGN_CHAR(p_sep_by_space); 8572166Sphantom M_ASSIGN_CHAR(n_cs_precedes); 8672166Sphantom M_ASSIGN_CHAR(n_sep_by_space); 8772166Sphantom M_ASSIGN_CHAR(p_sign_posn); 8872166Sphantom M_ASSIGN_CHAR(n_sign_posn); 89104711Stjr M_ASSIGN_CHAR(int_p_cs_precedes); 90104711Stjr M_ASSIGN_CHAR(int_n_cs_precedes); 91104711Stjr M_ASSIGN_CHAR(int_p_sep_by_space); 92104711Stjr M_ASSIGN_CHAR(int_n_sep_by_space); 93104711Stjr M_ASSIGN_CHAR(int_p_sign_posn); 94104711Stjr M_ASSIGN_CHAR(int_n_sign_posn); 95227753Stheraven loc->monetary_locale_changed = 0; 9672166Sphantom } 9772166Sphantom 98227753Stheraven if (loc->numeric_locale_changed) { 9972166Sphantom /* LC_NUMERIC part */ 10072166Sphantom struct lc_numeric_T * nptr; 10172166Sphantom 102227753Stheraven#define N_ASSIGN_STR(NAME) (ret->NAME = (char*)nptr->NAME) 10372166Sphantom 104227753Stheraven nptr = __get_current_numeric_locale(loc); 10572166Sphantom N_ASSIGN_STR(decimal_point); 10672166Sphantom N_ASSIGN_STR(thousands_sep); 10772321Sphantom N_ASSIGN_STR(grouping); 108227753Stheraven loc->numeric_locale_changed = 0; 10972166Sphantom } 11072166Sphantom 111227753Stheraven return ret; 1121573Srgrimes} 113227753Stheravenstruct lconv * 114227753Stheravenlocaleconv(void) 115227753Stheraven{ 116227753Stheraven return localeconv_l(__get_locale()); 117227753Stheraven} 118