exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / localeconv.c
blob10fc7b748bc78fdb5a1cc6d3898e9eaa56ab15a2
1 /* Query locale dependent information for formatting numbers.
2 Copyright (C) 2012-2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <locale.h>
22 #include <limits.h>
24 #if HAVE_STRUCT_LCONV_DECIMAL_POINT
26 # define FIX_CHAR_VALUE(x) ((x) >= 0 ? (x) : CHAR_MAX)
28 /* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_*
29 members or where fields of type 'char' are set to -1 instead of CHAR_MAX. */
31 struct lconv *
32 localeconv (void)
34 static struct lconv result;
35 # undef lconv
36 # undef localeconv
37 struct lconv *sys_result = localeconv ();
39 result.decimal_point = sys_result->decimal_point;
40 result.thousands_sep = sys_result->thousands_sep;
41 result.grouping = sys_result->grouping;
42 result.mon_decimal_point = sys_result->mon_decimal_point;
43 result.mon_thousands_sep = sys_result->mon_thousands_sep;
44 result.mon_grouping = sys_result->mon_grouping;
45 result.positive_sign = sys_result->positive_sign;
46 result.negative_sign = sys_result->negative_sign;
47 result.currency_symbol = sys_result->currency_symbol;
48 result.frac_digits = FIX_CHAR_VALUE (sys_result->frac_digits);
49 result.p_cs_precedes = FIX_CHAR_VALUE (sys_result->p_cs_precedes);
50 result.p_sign_posn = FIX_CHAR_VALUE (sys_result->p_sign_posn);
51 result.p_sep_by_space = FIX_CHAR_VALUE (sys_result->p_sep_by_space);
52 result.n_cs_precedes = FIX_CHAR_VALUE (sys_result->n_cs_precedes);
53 result.n_sign_posn = FIX_CHAR_VALUE (sys_result->n_sign_posn);
54 result.n_sep_by_space = FIX_CHAR_VALUE (sys_result->n_sep_by_space);
55 result.int_curr_symbol = sys_result->int_curr_symbol;
56 result.int_frac_digits = FIX_CHAR_VALUE (sys_result->int_frac_digits);
57 # if HAVE_STRUCT_LCONV_INT_P_CS_PRECEDES
58 result.int_p_cs_precedes = FIX_CHAR_VALUE (sys_result->int_p_cs_precedes);
59 result.int_p_sign_posn = FIX_CHAR_VALUE (sys_result->int_p_sign_posn);
60 result.int_p_sep_by_space = FIX_CHAR_VALUE (sys_result->int_p_sep_by_space);
61 result.int_n_cs_precedes = FIX_CHAR_VALUE (sys_result->int_n_cs_precedes);
62 result.int_n_sign_posn = FIX_CHAR_VALUE (sys_result->int_n_sign_posn);
63 result.int_n_sep_by_space = FIX_CHAR_VALUE (sys_result->int_n_sep_by_space);
64 # else
65 result.int_p_cs_precedes = FIX_CHAR_VALUE (sys_result->p_cs_precedes);
66 result.int_p_sign_posn = FIX_CHAR_VALUE (sys_result->p_sign_posn);
67 result.int_p_sep_by_space = FIX_CHAR_VALUE (sys_result->p_sep_by_space);
68 result.int_n_cs_precedes = FIX_CHAR_VALUE (sys_result->n_cs_precedes);
69 result.int_n_sign_posn = FIX_CHAR_VALUE (sys_result->n_sign_posn);
70 result.int_n_sep_by_space = FIX_CHAR_VALUE (sys_result->n_sep_by_space);
71 # endif
73 return &result;
76 #else
78 /* Override for platforms where 'struct lconv' is a dummy. */
80 struct lconv *
81 localeconv (void)
83 static /*const*/ struct lconv result =
85 /* decimal_point */ ".",
86 /* thousands_sep */ "",
87 /* grouping */ "",
88 /* mon_decimal_point */ "",
89 /* mon_thousands_sep */ "",
90 /* mon_grouping */ "",
91 /* positive_sign */ "",
92 /* negative_sign */ "",
93 /* currency_symbol */ "",
94 /* frac_digits */ CHAR_MAX,
95 /* p_cs_precedes */ CHAR_MAX,
96 /* p_sign_posn */ CHAR_MAX,
97 /* p_sep_by_space */ CHAR_MAX,
98 /* n_cs_precedes */ CHAR_MAX,
99 /* n_sign_posn */ CHAR_MAX,
100 /* n_sep_by_space */ CHAR_MAX,
101 /* int_curr_symbol */ "",
102 /* int_frac_digits */ CHAR_MAX,
103 /* int_p_cs_precedes */ CHAR_MAX,
104 /* int_p_sign_posn */ CHAR_MAX,
105 /* int_p_sep_by_space */ CHAR_MAX,
106 /* int_n_cs_precedes */ CHAR_MAX,
107 /* int_n_sign_posn */ CHAR_MAX,
108 /* int_n_sep_by_space */ CHAR_MAX
111 return &result;
114 #endif