14297a3b0SGarrett D'Amore /* 2*2d08521bSGarrett D'Amore * Copyright 2014 Garrett D'Amore. 36b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 44297a3b0SGarrett D'Amore * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org> 54297a3b0SGarrett D'Amore * All rights reserved. 64297a3b0SGarrett D'Amore * 74297a3b0SGarrett D'Amore * Redistribution and use in source and binary forms, with or without 84297a3b0SGarrett D'Amore * modification, are permitted provided that the following conditions 94297a3b0SGarrett D'Amore * are met: 104297a3b0SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright 114297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer. 124297a3b0SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright 134297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the 144297a3b0SGarrett D'Amore * documentation and/or other materials provided with the distribution. 154297a3b0SGarrett D'Amore * 164297a3b0SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 174297a3b0SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 184297a3b0SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 194297a3b0SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 204297a3b0SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 214297a3b0SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 224297a3b0SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 234297a3b0SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 244297a3b0SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 254297a3b0SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 264297a3b0SGarrett D'Amore * SUCH DAMAGE. 274297a3b0SGarrett D'Amore */ 284297a3b0SGarrett D'Amore 294297a3b0SGarrett D'Amore #include "lint.h" 304297a3b0SGarrett D'Amore #include <limits.h> 31*2d08521bSGarrett D'Amore #include <errno.h> 324297a3b0SGarrett D'Amore #include "ldpart.h" 334297a3b0SGarrett D'Amore #include "lnumeric.h" 34*2d08521bSGarrett D'Amore #include "localeimpl.h" 354297a3b0SGarrett D'Amore 364297a3b0SGarrett D'Amore extern const char *__fix_locale_grouping_str(const char *); 374297a3b0SGarrett D'Amore 38*2d08521bSGarrett D'Amore #define LCNUMERIC_SIZE (sizeof (struct lc_numeric) / sizeof (char *)) 394297a3b0SGarrett D'Amore 404297a3b0SGarrett D'Amore static char numempty[] = { CHAR_MAX, '\0' }; 414297a3b0SGarrett D'Amore 42*2d08521bSGarrett D'Amore struct lc_numeric lc_numeric_posix = { 434297a3b0SGarrett D'Amore ".", /* decimal_point */ 444297a3b0SGarrett D'Amore "", /* thousands_sep */ 454297a3b0SGarrett D'Amore numempty /* grouping */ 464297a3b0SGarrett D'Amore }; 474297a3b0SGarrett D'Amore 48*2d08521bSGarrett D'Amore struct locdata __posix_numeric_locdata = { 49*2d08521bSGarrett D'Amore .l_lname = "C", 50*2d08521bSGarrett D'Amore .l_data = { &lc_numeric_posix } 51*2d08521bSGarrett D'Amore }; 524297a3b0SGarrett D'Amore 53*2d08521bSGarrett D'Amore 54*2d08521bSGarrett D'Amore /* 55*2d08521bSGarrett D'Amore * Return the locale's numeric locdata structure. 56*2d08521bSGarrett D'Amore */ 57*2d08521bSGarrett D'Amore struct locdata * 58*2d08521bSGarrett D'Amore __lc_numeric_load(const char *name) 594297a3b0SGarrett D'Amore { 60*2d08521bSGarrett D'Amore struct locdata *ldata; 61*2d08521bSGarrett D'Amore struct lc_numeric *lnum; 624297a3b0SGarrett D'Amore int ret; 634297a3b0SGarrett D'Amore 64*2d08521bSGarrett D'Amore if ((ldata = __locdata_alloc(name, sizeof (*lnum))) == NULL) { 65*2d08521bSGarrett D'Amore errno = EINVAL; 66*2d08521bSGarrett D'Amore return (NULL); 67*2d08521bSGarrett D'Amore } 68*2d08521bSGarrett D'Amore lnum = ldata->l_data[0]; 69762f6727SJason King 70*2d08521bSGarrett D'Amore ret = __part_load_locale(name, (char **)&ldata->l_data[1], 71*2d08521bSGarrett D'Amore "LC_NUMERIC", LCNUMERIC_SIZE, LCNUMERIC_SIZE, (const char **)lnum); 72*2d08521bSGarrett D'Amore 73*2d08521bSGarrett D'Amore if (ret != _LDP_LOADED) { 74*2d08521bSGarrett D'Amore __locdata_free(ldata); 75*2d08521bSGarrett D'Amore return (NULL); 76*2d08521bSGarrett D'Amore } 77*2d08521bSGarrett D'Amore 784297a3b0SGarrett D'Amore /* Can't be empty according to C99 */ 79*2d08521bSGarrett D'Amore if (*lnum->decimal_point == '\0') 80*2d08521bSGarrett D'Amore lnum->decimal_point = lc_numeric_posix.decimal_point; 81*2d08521bSGarrett D'Amore lnum->grouping = __fix_locale_grouping_str(lnum->grouping); 824297a3b0SGarrett D'Amore 83*2d08521bSGarrett D'Amore return (ldata); 844297a3b0SGarrett D'Amore } 85