lnumeric.c revision 6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648
2N/A/*
2N/A * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
2N/A * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
2N/A * All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions
2N/A * are met:
2N/A * 1. Redistributions of source code must retain the above copyright
2N/A * notice, this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright
2N/A * notice, this list of conditions and the following disclaimer in the
2N/A * documentation and/or other materials provided with the distribution.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2N/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2N/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2N/A * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2N/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2N/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2N/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2N/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2N/A * SUCH DAMAGE.
2N/A */
2N/A
2N/A#include "lint.h"
2N/A#include <limits.h>
2N/A#include "ldpart.h"
2N/A#include "lnumeric.h"
2N/A#include "../i18n/_locale.h"
2N/A
2N/Aextern int __nlocale_changed;
2N/Aextern const char *__fix_locale_grouping_str(const char *);
2N/A
2N/A#define LCNUMERIC_SIZE (sizeof (struct lc_numeric_T) / sizeof (char *))
2N/A
2N/Astatic char numempty[] = { CHAR_MAX, '\0' };
2N/A
2N/Astatic const struct lc_numeric_T _C_numeric_locale = {
2N/A ".", /* decimal_point */
2N/A "", /* thousands_sep */
2N/A numempty /* grouping */
2N/A};
2N/A
2N/Astatic struct lc_numeric_T _numeric_locale;
2N/Astatic int _numeric_using_locale;
2N/Astatic char *_numeric_locale_buf;
2N/A
2N/Aint
2N/A__numeric_load_locale(const char *name)
2N/A{
2N/A int ret;
2N/A
2N/A ret = __part_load_locale(name, &_numeric_using_locale,
2N/A &_numeric_locale_buf, "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE,
2N/A (const char **)&_numeric_locale);
2N/A if (ret != _LDP_ERROR)
2N/A __nlocale_changed = 1;
2N/A if (ret == _LDP_LOADED) {
2N/A /* Can't be empty according to C99 */
2N/A if (*_numeric_locale.decimal_point == '\0')
2N/A _numeric_locale.decimal_point =
2N/A _C_numeric_locale.decimal_point;
2N/A _numeric_locale.grouping =
2N/A __fix_locale_grouping_str(_numeric_locale.grouping);
2N/A
2N/A /* This is Solaris legacy, required for _doprnt */
2N/A _numeric[0] = *_numeric_locale.decimal_point;
2N/A _numeric[1] = *_numeric_locale.grouping;
2N/A }
2N/A return (ret);
2N/A}
2N/A
2N/Astruct lc_numeric_T *
2N/A__get_current_numeric_locale(void)
2N/A{
2N/A return (_numeric_using_locale ? &_numeric_locale :
2N/A (struct lc_numeric_T *)&_C_numeric_locale);
2N/A}
2N/A