tools/llvm: Do not build with symbols
[minix3.git] / lib / libc / locale / nl_langinfo.c
blob7d0c2f90673242891add24f3a99abf1c7f49ed07
1 /* $NetBSD: nl_langinfo.c,v 1.17 2013/08/20 19:58:30 joerg 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 __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>
35 #include <langinfo.h>
36 #include <stddef.h>
37 #define __SETLOCALE_SOURCE__
38 #include <locale.h>
39 #include <stdlib.h>
40 #include <string.h>
42 #include "runetype_local.h"
43 #include "setlocale_local.h"
45 static const char langinfo_category[] = {
46 [ D_T_FMT ] = LC_TIME,
47 [ D_FMT ] = LC_TIME,
48 [ T_FMT ] = LC_TIME,
49 [ T_FMT_AMPM ] = LC_TIME,
50 [ AM_STR ] = LC_TIME,
51 [ PM_STR ] = LC_TIME,
52 [ DAY_1 ] = LC_TIME,
53 [ DAY_2 ] = LC_TIME,
54 [ DAY_3 ] = LC_TIME,
55 [ DAY_4 ] = LC_TIME,
56 [ DAY_5 ] = LC_TIME,
57 [ DAY_6 ] = LC_TIME,
58 [ DAY_7 ] = 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,
66 [ MON_1 ] = LC_TIME,
67 [ MON_2 ] = LC_TIME,
68 [ MON_3 ] = LC_TIME,
69 [ MON_4 ] = LC_TIME,
70 [ MON_5 ] = LC_TIME,
71 [ MON_6 ] = LC_TIME,
72 [ MON_7 ] = LC_TIME,
73 [ MON_8 ] = LC_TIME,
74 [ MON_9 ] = LC_TIME,
75 [ MON_10 ] = LC_TIME,
76 [ MON_11 ] = LC_TIME,
77 [ MON_12 ] = 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,
96 [ CRNCYSTR ] = 0,
97 [ CODESET ] = LC_CTYPE,
98 [ ERA ] = 0,
99 [ ERA_D_FMT ] = 0,
100 [ ERA_D_T_FMT ] = 0,
101 [ ERA_T_FMT ] = 0,
102 [ ALT_DIGITS ] = 0,
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),
156 [ CRNCYSTR ] = 0,
157 [ CODESET ] = offsetof(_RuneLocale, rl_codeset),
158 [ ERA ] = 0,
159 [ ERA_D_FMT ] = 0,
160 [ ERA_D_T_FMT ] = 0,
161 [ ERA_T_FMT ] = 0,
162 [ ALT_DIGITS ] = 0,
165 __weak_alias(nl_langinfo_l, _nl_langinfo_l)
167 char *
168 nl_langinfo(nl_item item)
171 return nl_langinfo_l(item, _current_locale());
174 char *
175 nl_langinfo_l(nl_item item, locale_t loc)
177 char *s;
178 int category;
179 size_t offset;
181 if (item < 0 || item >= (long)__arraycount(langinfo_category))
182 return __UNCONST(""); /* Outside the defined range */
184 category = langinfo_category[item];
185 if (category == 0)
186 return __UNCONST(""); /* Not in use */
187 offset = langinfo_offset[item];
189 memcpy(&s, (char *)loc->part_impl[category] + offset, sizeof(s));
190 if (s == NULL)
191 return __UNCONST("");
192 else
193 return s;