coverity appeasement
[minix.git] / lib / libc / locale / global_locale.c
blob34370bf4ce127a1110f5eb035a5231bbe617fa63
1 /* $NetBSD: global_locale.c,v 1.11 2010/06/19 13:26:52 tnozaki Exp $ */
3 /*-
4 * Copyright (c)2008 Citrus Project,
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 #if defined(LIBC_SCCS) && !defined(lint)
31 __RCSID("$NetBSD: global_locale.c,v 1.11 2010/06/19 13:26:52 tnozaki Exp $");
32 #endif /* LIBC_SCCS and not lint */
34 #include <sys/types.h>
35 #include <sys/ctype_bits.h>
36 #include <sys/localedef.h>
37 #include <langinfo.h>
38 #include <limits.h>
39 #define __SETLOCALE_SOURCE__
40 #include <locale.h>
41 #include <stdlib.h>
42 #ifdef WITH_RUNE
43 #include "runetype_local.h"
44 #else
45 #include "bsdctype_local.h"
46 #endif
48 #include "setlocale_local.h"
50 static struct lconv _global_ldata = {
51 .decimal_point = __UNCONST("."),
52 .thousands_sep = __UNCONST(""),
53 .grouping = __UNCONST(""),
54 .int_curr_symbol = __UNCONST(""),
55 .currency_symbol = __UNCONST(""),
56 .mon_decimal_point = __UNCONST(""),
57 .mon_thousands_sep = __UNCONST(""),
58 .mon_grouping = __UNCONST(""),
59 .positive_sign = __UNCONST(""),
60 .negative_sign = __UNCONST(""),
61 .int_frac_digits = CHAR_MAX,
62 .frac_digits = CHAR_MAX,
63 .p_cs_precedes = CHAR_MAX,
64 .p_sep_by_space = CHAR_MAX,
65 .n_cs_precedes = CHAR_MAX,
66 .n_sep_by_space = CHAR_MAX,
67 .p_sign_posn = CHAR_MAX,
68 .n_sign_posn = CHAR_MAX,
69 .int_p_cs_precedes = CHAR_MAX,
70 .int_n_cs_precedes = CHAR_MAX,
71 .int_p_sep_by_space = CHAR_MAX,
72 .int_n_sep_by_space = CHAR_MAX,
73 .int_p_sign_posn = CHAR_MAX,
74 .int_n_sign_posn = CHAR_MAX,
77 static const char *_global_items[(size_t)ALT_DIGITS + 1] = {
78 [(size_t)D_T_FMT ] = "%a %b %e %H:%M:%S %Y",
79 [(size_t)D_FMT ] = "%m/%d/%y",
80 [(size_t)T_FMT ] = "%H:%M:%S",
81 [(size_t)T_FMT_AMPM ] = "%I:%M:%S %p",
82 [(size_t)AM_STR ] = "AM",
83 [(size_t)PM_STR ] = "PM",
84 [(size_t)DAY_1 ] = "Sun",
85 [(size_t)DAY_2 ] = "Mon",
86 [(size_t)DAY_3 ] = "Tue",
87 [(size_t)DAY_4 ] = "Wed",
88 [(size_t)DAY_5 ] = "Thu",
89 [(size_t)DAY_6 ] = "Fri",
90 [(size_t)DAY_7 ] = "Sat",
91 [(size_t)ABDAY_1 ] = "Sunday",
92 [(size_t)ABDAY_2 ] = "Monday",
93 [(size_t)ABDAY_3 ] = "Tuesday",
94 [(size_t)ABDAY_4 ] = "Wednesday",
95 [(size_t)ABDAY_5 ] = "Thursday",
96 [(size_t)ABDAY_6 ] = "Friday",
97 [(size_t)ABDAY_7 ] = "Saturday",
98 [(size_t)MON_1 ] = "Jan",
99 [(size_t)MON_2 ] = "Feb",
100 [(size_t)MON_3 ] = "Mar",
101 [(size_t)MON_4 ] = "Apr",
102 [(size_t)MON_5 ] = "May",
103 [(size_t)MON_6 ] = "Jun",
104 [(size_t)MON_7 ] = "Jul",
105 [(size_t)MON_8 ] = "Aug",
106 [(size_t)MON_9 ] = "Sep",
107 [(size_t)MON_10 ] = "Oct",
108 [(size_t)MON_11 ] = "Nov",
109 [(size_t)MON_12 ] = "Dec",
110 [(size_t)ABMON_1 ] = "January",
111 [(size_t)ABMON_2 ] = "February",
112 [(size_t)ABMON_3 ] = "March",
113 [(size_t)ABMON_4 ] = "April",
114 [(size_t)ABMON_5 ] = "May",
115 [(size_t)ABMON_6 ] = "June",
116 [(size_t)ABMON_7 ] = "July",
117 [(size_t)ABMON_8 ] = "August",
118 [(size_t)ABMON_9 ] = "September",
119 [(size_t)ABMON_10 ] = "October",
120 [(size_t)ABMON_11 ] = "November",
121 [(size_t)ABMON_12 ] = "December",
122 [(size_t)RADIXCHAR ] = ".",
123 [(size_t)THOUSEP ] = "",
124 [(size_t)YESSTR ] = "yes",
125 [(size_t)YESEXPR ] = "^[Yy]",
126 [(size_t)NOSTR ] = "no",
127 [(size_t)NOEXPR ] = "^[Nn]",
128 [(size_t)CRNCYSTR ] = NULL,
129 [(size_t)CODESET ] = "646",
130 [(size_t)ERA ] = NULL,
131 [(size_t)ERA_D_FMT ] = NULL,
132 [(size_t)ERA_D_T_FMT] = NULL,
133 [(size_t)ERA_T_FMT ] = NULL,
134 [(size_t)ALT_DIGITS ] = NULL,
137 static struct _locale_cache_t _global_cache = {
138 .ctype_tab = (const unsigned char *)&_C_ctype_[0],
139 .tolower_tab = (const short *)&_C_tolower_[0],
140 .toupper_tab = (const short *)&_C_toupper_[0],
141 .mb_cur_max = (size_t)1,
142 .ldata = &_global_ldata,
143 .items = &_global_items[0],
146 struct _locale_impl_t _global_locale = {
147 .cache = &_global_cache,
148 .query = { _C_LOCALE },
149 .part_name = {
150 [(size_t)LC_ALL ] = _C_LOCALE,
151 [(size_t)LC_COLLATE ] = _C_LOCALE,
152 [(size_t)LC_CTYPE ] = _C_LOCALE,
153 [(size_t)LC_MONETARY] = _C_LOCALE,
154 [(size_t)LC_NUMERIC ] = _C_LOCALE,
155 [(size_t)LC_TIME ] = _C_LOCALE,
156 [(size_t)LC_MESSAGES] = _C_LOCALE,
158 .part_impl = {
159 [(size_t)LC_ALL ] = (_locale_part_t)NULL,
160 [(size_t)LC_COLLATE ] = (_locale_part_t)NULL,
161 [(size_t)LC_CTYPE ] = (_locale_part_t)
162 #ifdef WITH_RUNE
163 __UNCONST(&_DefaultRuneLocale),
164 #else
165 __UNCONST(&_DefaultBSDCTypeLocale),
166 #endif
167 [(size_t)LC_MONETARY] = (_locale_part_t)
168 __UNCONST(&_DefaultMonetaryLocale),
169 [(size_t)LC_NUMERIC ] = (_locale_part_t)
170 __UNCONST(&_DefaultNumericLocale),
171 [(size_t)LC_MESSAGES] = (_locale_part_t)
172 __UNCONST(&_DefaultMessagesLocale),