1 /* $NetBSD: nl_langinfo.c,v 1.17 2013/08/20 19:58:30 joerg Exp $ */
4 * Copyright (c)2008 Citrus Project,
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: nl_langinfo.c,v 1.17 2013/08/20 19:58:30 joerg Exp $");
32 #include "namespace.h"
33 #include <sys/types.h>
34 #include <sys/localedef.h>
37 #define __SETLOCALE_SOURCE__
42 #include "runetype_local.h"
43 #include "setlocale_local.h"
45 static const char langinfo_category
[] = {
46 [ D_T_FMT
] = LC_TIME
,
49 [ T_FMT_AMPM
] = LC_TIME
,
59 [ ABDAY_1
] = LC_TIME
,
60 [ ABDAY_2
] = LC_TIME
,
61 [ ABDAY_3
] = LC_TIME
,
62 [ ABDAY_4
] = LC_TIME
,
63 [ ABDAY_5
] = LC_TIME
,
64 [ ABDAY_6
] = LC_TIME
,
65 [ ABDAY_7
] = LC_TIME
,
78 [ ABMON_1
] = LC_TIME
,
79 [ ABMON_2
] = LC_TIME
,
80 [ ABMON_3
] = LC_TIME
,
81 [ ABMON_4
] = LC_TIME
,
82 [ ABMON_5
] = LC_TIME
,
83 [ ABMON_6
] = LC_TIME
,
84 [ ABMON_7
] = LC_TIME
,
85 [ ABMON_8
] = LC_TIME
,
86 [ ABMON_9
] = LC_TIME
,
87 [ ABMON_10
] = LC_TIME
,
88 [ ABMON_11
] = LC_TIME
,
89 [ ABMON_12
] = LC_TIME
,
90 [ RADIXCHAR
] = LC_NUMERIC
,
91 [ THOUSEP
] = LC_NUMERIC
,
92 [ YESSTR
] = LC_MESSAGES
,
93 [ YESEXPR
] = LC_MESSAGES
,
94 [ NOSTR
] = LC_MESSAGES
,
95 [ NOEXPR
] = LC_MESSAGES
,
97 [ CODESET
] = LC_CTYPE
,
105 static const uint16_t langinfo_offset
[] = {
106 [ D_T_FMT
] = offsetof(_TimeLocale
, d_t_fmt
),
107 [ D_FMT
] = offsetof(_TimeLocale
, d_fmt
),
108 [ T_FMT
] = offsetof(_TimeLocale
, t_fmt
),
109 [ T_FMT_AMPM
] = offsetof(_TimeLocale
, t_fmt_ampm
),
110 [ AM_STR
] = offsetof(_TimeLocale
, am_pm
[0]),
111 [ PM_STR
] = offsetof(_TimeLocale
, am_pm
[1]),
112 [ DAY_1
] = offsetof(_TimeLocale
, day
[0]),
113 [ DAY_2
] = offsetof(_TimeLocale
, day
[1]),
114 [ DAY_3
] = offsetof(_TimeLocale
, day
[2]),
115 [ DAY_4
] = offsetof(_TimeLocale
, day
[3]),
116 [ DAY_5
] = offsetof(_TimeLocale
, day
[4]),
117 [ DAY_6
] = offsetof(_TimeLocale
, day
[5]),
118 [ DAY_7
] = offsetof(_TimeLocale
, day
[6]),
119 [ ABDAY_1
] = offsetof(_TimeLocale
, abday
[0]),
120 [ ABDAY_2
] = offsetof(_TimeLocale
, abday
[1]),
121 [ ABDAY_3
] = offsetof(_TimeLocale
, abday
[2]),
122 [ ABDAY_4
] = offsetof(_TimeLocale
, abday
[3]),
123 [ ABDAY_5
] = offsetof(_TimeLocale
, abday
[4]),
124 [ ABDAY_6
] = offsetof(_TimeLocale
, abday
[5]),
125 [ ABDAY_7
] = offsetof(_TimeLocale
, abday
[6]),
126 [ MON_1
] = offsetof(_TimeLocale
, mon
[0]),
127 [ MON_2
] = offsetof(_TimeLocale
, mon
[1]),
128 [ MON_3
] = offsetof(_TimeLocale
, mon
[2]),
129 [ MON_4
] = offsetof(_TimeLocale
, mon
[3]),
130 [ MON_5
] = offsetof(_TimeLocale
, mon
[4]),
131 [ MON_6
] = offsetof(_TimeLocale
, mon
[5]),
132 [ MON_7
] = offsetof(_TimeLocale
, mon
[6]),
133 [ MON_8
] = offsetof(_TimeLocale
, mon
[7]),
134 [ MON_9
] = offsetof(_TimeLocale
, mon
[8]),
135 [ MON_10
] = offsetof(_TimeLocale
, mon
[9]),
136 [ MON_11
] = offsetof(_TimeLocale
, mon
[10]),
137 [ MON_12
] = offsetof(_TimeLocale
, mon
[11]),
138 [ ABMON_1
] = offsetof(_TimeLocale
, abmon
[0]),
139 [ ABMON_2
] = offsetof(_TimeLocale
, abmon
[1]),
140 [ ABMON_3
] = offsetof(_TimeLocale
, abmon
[2]),
141 [ ABMON_4
] = offsetof(_TimeLocale
, abmon
[3]),
142 [ ABMON_5
] = offsetof(_TimeLocale
, abmon
[4]),
143 [ ABMON_6
] = offsetof(_TimeLocale
, abmon
[5]),
144 [ ABMON_7
] = offsetof(_TimeLocale
, abmon
[6]),
145 [ ABMON_8
] = offsetof(_TimeLocale
, abmon
[7]),
146 [ ABMON_9
] = offsetof(_TimeLocale
, abmon
[8]),
147 [ ABMON_10
] = offsetof(_TimeLocale
, abmon
[9]),
148 [ ABMON_11
] = offsetof(_TimeLocale
, abmon
[10]),
149 [ ABMON_12
] = offsetof(_TimeLocale
, abmon
[11]),
150 [ RADIXCHAR
] = offsetof(_NumericLocale
, decimal_point
),
151 [ THOUSEP
] = offsetof(_NumericLocale
, thousands_sep
),
152 [ YESSTR
] = offsetof(_MessagesLocale
, yesstr
),
153 [ YESEXPR
] = offsetof(_MessagesLocale
, yesexpr
),
154 [ NOSTR
] = offsetof(_MessagesLocale
, nostr
),
155 [ NOEXPR
] = offsetof(_MessagesLocale
, noexpr
),
157 [ CODESET
] = offsetof(_RuneLocale
, rl_codeset
),
165 __weak_alias(nl_langinfo_l
, _nl_langinfo_l
)
168 nl_langinfo(nl_item item
)
171 return nl_langinfo_l(item
, _current_locale());
175 nl_langinfo_l(nl_item item
, locale_t loc
)
181 if (item
< 0 || item
>= (long)__arraycount(langinfo_category
))
182 return __UNCONST(""); /* Outside the defined range */
184 category
= langinfo_category
[item
];
186 return __UNCONST(""); /* Not in use */
187 offset
= langinfo_offset
[item
];
189 memcpy(&s
, (char *)loc
->part_impl
[category
] + offset
, sizeof(s
));
191 return __UNCONST("");