nl_langinfo.c revision 1.17 1 1.17 joerg /* $NetBSD: nl_langinfo.c,v 1.17 2013/08/20 19:58:30 joerg Exp $ */
2 1.4 kleink
3 1.12 tnozaki /*-
4 1.12 tnozaki * Copyright (c)2008 Citrus Project,
5 1.12 tnozaki * All rights reserved.
6 1.12 tnozaki *
7 1.12 tnozaki * Redistribution and use in source and binary forms, with or without
8 1.12 tnozaki * modification, are permitted provided that the following conditions
9 1.12 tnozaki * are met:
10 1.12 tnozaki * 1. Redistributions of source code must retain the above copyright
11 1.12 tnozaki * notice, this list of conditions and the following disclaimer.
12 1.12 tnozaki * 2. Redistributions in binary form must reproduce the above copyright
13 1.12 tnozaki * notice, this list of conditions and the following disclaimer in the
14 1.12 tnozaki * documentation and/or other materials provided with the distribution.
15 1.12 tnozaki *
16 1.12 tnozaki * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.12 tnozaki * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.12 tnozaki * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.12 tnozaki * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.12 tnozaki * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.12 tnozaki * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.12 tnozaki * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.12 tnozaki * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.12 tnozaki * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.12 tnozaki * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.12 tnozaki * SUCH DAMAGE.
27 1.1 jtc */
28 1.1 jtc
29 1.5 christos #include <sys/cdefs.h>
30 1.17 joerg __RCSID("$NetBSD: nl_langinfo.c,v 1.17 2013/08/20 19:58:30 joerg Exp $");
31 1.1 jtc
32 1.16 joerg #include "namespace.h"
33 1.12 tnozaki #include <sys/types.h>
34 1.17 joerg #include <sys/localedef.h>
35 1.12 tnozaki #include <langinfo.h>
36 1.17 joerg #include <stddef.h>
37 1.12 tnozaki #define __SETLOCALE_SOURCE__
38 1.1 jtc #include <locale.h>
39 1.12 tnozaki #include <stdlib.h>
40 1.17 joerg #include <string.h>
41 1.12 tnozaki
42 1.17 joerg #include "runetype_local.h"
43 1.12 tnozaki #include "setlocale_local.h"
44 1.1 jtc
45 1.17 joerg static const char langinfo_category[] = {
46 1.17 joerg [ D_T_FMT ] = LC_TIME,
47 1.17 joerg [ D_FMT ] = LC_TIME,
48 1.17 joerg [ T_FMT ] = LC_TIME,
49 1.17 joerg [ T_FMT_AMPM ] = LC_TIME,
50 1.17 joerg [ AM_STR ] = LC_TIME,
51 1.17 joerg [ PM_STR ] = LC_TIME,
52 1.17 joerg [ DAY_1 ] = LC_TIME,
53 1.17 joerg [ DAY_2 ] = LC_TIME,
54 1.17 joerg [ DAY_3 ] = LC_TIME,
55 1.17 joerg [ DAY_4 ] = LC_TIME,
56 1.17 joerg [ DAY_5 ] = LC_TIME,
57 1.17 joerg [ DAY_6 ] = LC_TIME,
58 1.17 joerg [ DAY_7 ] = LC_TIME,
59 1.17 joerg [ ABDAY_1 ] = LC_TIME,
60 1.17 joerg [ ABDAY_2 ] = LC_TIME,
61 1.17 joerg [ ABDAY_3 ] = LC_TIME,
62 1.17 joerg [ ABDAY_4 ] = LC_TIME,
63 1.17 joerg [ ABDAY_5 ] = LC_TIME,
64 1.17 joerg [ ABDAY_6 ] = LC_TIME,
65 1.17 joerg [ ABDAY_7 ] = LC_TIME,
66 1.17 joerg [ MON_1 ] = LC_TIME,
67 1.17 joerg [ MON_2 ] = LC_TIME,
68 1.17 joerg [ MON_3 ] = LC_TIME,
69 1.17 joerg [ MON_4 ] = LC_TIME,
70 1.17 joerg [ MON_5 ] = LC_TIME,
71 1.17 joerg [ MON_6 ] = LC_TIME,
72 1.17 joerg [ MON_7 ] = LC_TIME,
73 1.17 joerg [ MON_8 ] = LC_TIME,
74 1.17 joerg [ MON_9 ] = LC_TIME,
75 1.17 joerg [ MON_10 ] = LC_TIME,
76 1.17 joerg [ MON_11 ] = LC_TIME,
77 1.17 joerg [ MON_12 ] = LC_TIME,
78 1.17 joerg [ ABMON_1 ] = LC_TIME,
79 1.17 joerg [ ABMON_2 ] = LC_TIME,
80 1.17 joerg [ ABMON_3 ] = LC_TIME,
81 1.17 joerg [ ABMON_4 ] = LC_TIME,
82 1.17 joerg [ ABMON_5 ] = LC_TIME,
83 1.17 joerg [ ABMON_6 ] = LC_TIME,
84 1.17 joerg [ ABMON_7 ] = LC_TIME,
85 1.17 joerg [ ABMON_8 ] = LC_TIME,
86 1.17 joerg [ ABMON_9 ] = LC_TIME,
87 1.17 joerg [ ABMON_10 ] = LC_TIME,
88 1.17 joerg [ ABMON_11 ] = LC_TIME,
89 1.17 joerg [ ABMON_12 ] = LC_TIME,
90 1.17 joerg [ RADIXCHAR ] = LC_NUMERIC,
91 1.17 joerg [ THOUSEP ] = LC_NUMERIC,
92 1.17 joerg [ YESSTR ] = LC_MESSAGES,
93 1.17 joerg [ YESEXPR ] = LC_MESSAGES,
94 1.17 joerg [ NOSTR ] = LC_MESSAGES,
95 1.17 joerg [ NOEXPR ] = LC_MESSAGES,
96 1.17 joerg [ CRNCYSTR ] = 0,
97 1.17 joerg [ CODESET ] = LC_CTYPE,
98 1.17 joerg [ ERA ] = 0,
99 1.17 joerg [ ERA_D_FMT ] = 0,
100 1.17 joerg [ ERA_D_T_FMT ] = 0,
101 1.17 joerg [ ERA_T_FMT ] = 0,
102 1.17 joerg [ ALT_DIGITS ] = 0,
103 1.17 joerg };
104 1.17 joerg
105 1.17 joerg static const uint16_t langinfo_offset[] = {
106 1.17 joerg [ D_T_FMT ] = offsetof(_TimeLocale, d_t_fmt),
107 1.17 joerg [ D_FMT ] = offsetof(_TimeLocale, d_fmt),
108 1.17 joerg [ T_FMT ] = offsetof(_TimeLocale, t_fmt),
109 1.17 joerg [ T_FMT_AMPM ] = offsetof(_TimeLocale, t_fmt_ampm),
110 1.17 joerg [ AM_STR ] = offsetof(_TimeLocale, am_pm[0]),
111 1.17 joerg [ PM_STR ] = offsetof(_TimeLocale, am_pm[1]),
112 1.17 joerg [ DAY_1 ] = offsetof(_TimeLocale, day[0]),
113 1.17 joerg [ DAY_2 ] = offsetof(_TimeLocale, day[1]),
114 1.17 joerg [ DAY_3 ] = offsetof(_TimeLocale, day[2]),
115 1.17 joerg [ DAY_4 ] = offsetof(_TimeLocale, day[3]),
116 1.17 joerg [ DAY_5 ] = offsetof(_TimeLocale, day[4]),
117 1.17 joerg [ DAY_6 ] = offsetof(_TimeLocale, day[5]),
118 1.17 joerg [ DAY_7 ] = offsetof(_TimeLocale, day[6]),
119 1.17 joerg [ ABDAY_1 ] = offsetof(_TimeLocale, abday[0]),
120 1.17 joerg [ ABDAY_2 ] = offsetof(_TimeLocale, abday[1]),
121 1.17 joerg [ ABDAY_3 ] = offsetof(_TimeLocale, abday[2]),
122 1.17 joerg [ ABDAY_4 ] = offsetof(_TimeLocale, abday[3]),
123 1.17 joerg [ ABDAY_5 ] = offsetof(_TimeLocale, abday[4]),
124 1.17 joerg [ ABDAY_6 ] = offsetof(_TimeLocale, abday[5]),
125 1.17 joerg [ ABDAY_7 ] = offsetof(_TimeLocale, abday[6]),
126 1.17 joerg [ MON_1 ] = offsetof(_TimeLocale, mon[0]),
127 1.17 joerg [ MON_2 ] = offsetof(_TimeLocale, mon[1]),
128 1.17 joerg [ MON_3 ] = offsetof(_TimeLocale, mon[2]),
129 1.17 joerg [ MON_4 ] = offsetof(_TimeLocale, mon[3]),
130 1.17 joerg [ MON_5 ] = offsetof(_TimeLocale, mon[4]),
131 1.17 joerg [ MON_6 ] = offsetof(_TimeLocale, mon[5]),
132 1.17 joerg [ MON_7 ] = offsetof(_TimeLocale, mon[6]),
133 1.17 joerg [ MON_8 ] = offsetof(_TimeLocale, mon[7]),
134 1.17 joerg [ MON_9 ] = offsetof(_TimeLocale, mon[8]),
135 1.17 joerg [ MON_10 ] = offsetof(_TimeLocale, mon[9]),
136 1.17 joerg [ MON_11 ] = offsetof(_TimeLocale, mon[10]),
137 1.17 joerg [ MON_12 ] = offsetof(_TimeLocale, mon[11]),
138 1.17 joerg [ ABMON_1 ] = offsetof(_TimeLocale, abmon[0]),
139 1.17 joerg [ ABMON_2 ] = offsetof(_TimeLocale, abmon[1]),
140 1.17 joerg [ ABMON_3 ] = offsetof(_TimeLocale, abmon[2]),
141 1.17 joerg [ ABMON_4 ] = offsetof(_TimeLocale, abmon[3]),
142 1.17 joerg [ ABMON_5 ] = offsetof(_TimeLocale, abmon[4]),
143 1.17 joerg [ ABMON_6 ] = offsetof(_TimeLocale, abmon[5]),
144 1.17 joerg [ ABMON_7 ] = offsetof(_TimeLocale, abmon[6]),
145 1.17 joerg [ ABMON_8 ] = offsetof(_TimeLocale, abmon[7]),
146 1.17 joerg [ ABMON_9 ] = offsetof(_TimeLocale, abmon[8]),
147 1.17 joerg [ ABMON_10 ] = offsetof(_TimeLocale, abmon[9]),
148 1.17 joerg [ ABMON_11 ] = offsetof(_TimeLocale, abmon[10]),
149 1.17 joerg [ ABMON_12 ] = offsetof(_TimeLocale, abmon[11]),
150 1.17 joerg [ RADIXCHAR ] = offsetof(_NumericLocale, decimal_point),
151 1.17 joerg [ THOUSEP ] = offsetof(_NumericLocale, thousands_sep),
152 1.17 joerg [ YESSTR ] = offsetof(_MessagesLocale, yesstr),
153 1.17 joerg [ YESEXPR ] = offsetof(_MessagesLocale, yesexpr),
154 1.17 joerg [ NOSTR ] = offsetof(_MessagesLocale, nostr),
155 1.17 joerg [ NOEXPR ] = offsetof(_MessagesLocale, noexpr),
156 1.17 joerg [ CRNCYSTR ] = 0,
157 1.17 joerg [ CODESET ] = offsetof(_RuneLocale, rl_codeset),
158 1.17 joerg [ ERA ] = 0,
159 1.17 joerg [ ERA_D_FMT ] = 0,
160 1.17 joerg [ ERA_D_T_FMT ] = 0,
161 1.17 joerg [ ERA_T_FMT ] = 0,
162 1.17 joerg [ ALT_DIGITS ] = 0,
163 1.17 joerg };
164 1.17 joerg
165 1.16 joerg __weak_alias(nl_langinfo_l, _nl_langinfo_l)
166 1.16 joerg
167 1.1 jtc char *
168 1.12 tnozaki nl_langinfo(nl_item item)
169 1.1 jtc {
170 1.16 joerg
171 1.16 joerg return nl_langinfo_l(item, _current_locale());
172 1.16 joerg }
173 1.16 joerg
174 1.16 joerg char *
175 1.16 joerg nl_langinfo_l(nl_item item, locale_t loc)
176 1.16 joerg {
177 1.17 joerg char *s;
178 1.17 joerg int category;
179 1.17 joerg size_t offset;
180 1.17 joerg
181 1.17 joerg if (item < 0 || item >= (long)__arraycount(langinfo_category))
182 1.17 joerg return __UNCONST(""); /* Outside the defined range */
183 1.17 joerg
184 1.17 joerg category = langinfo_category[item];
185 1.17 joerg if (category == 0)
186 1.17 joerg return __UNCONST(""); /* Not in use */
187 1.17 joerg offset = langinfo_offset[item];
188 1.1 jtc
189 1.17 joerg memcpy(&s, (char *)loc->part_impl[category] + offset, sizeof(s));
190 1.12 tnozaki if (s == NULL)
191 1.17 joerg return __UNCONST("");
192 1.17 joerg else
193 1.17 joerg return s;
194 1.1 jtc }
195