kernel: scheduling fix for ARM
[minix.git] / lib / libc / citrus / citrus_lc_time.c
blob159a3ceddfb5a93d6e8526e4a2e081aa8f01f42c
1 /* $NetBSD: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 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: citrus_lc_time.c,v 1.6 2012/03/04 21:14:55 tnozaki Exp $");
32 #endif /* LIBC_SCCS and not lint */
34 #include "namespace.h"
35 #include "reentrant.h"
36 #include <sys/types.h>
37 #include <sys/localedef.h>
38 #include <sys/queue.h>
39 #include <assert.h>
40 #include <errno.h>
41 #include <langinfo.h>
42 #include <limits.h>
43 #define __SETLOCALE_SOURCE__
44 #include <locale.h>
45 #include <stddef.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
50 #include "setlocale_local.h"
52 #include "citrus_namespace.h"
53 #include "citrus_types.h"
54 #include "citrus_bcs.h"
55 #include "citrus_region.h"
56 #include "citrus_lookup.h"
57 #include "citrus_aliasname_local.h"
58 #include "citrus_module.h"
59 #include "citrus_mmap.h"
60 #include "citrus_hash.h"
61 #include "citrus_db.h"
62 #include "citrus_db_hash.h"
63 #include "citrus_memstream.h"
64 #include "runetype_local.h"
67 * macro required by all template headers
69 #define _PREFIX(name) __CONCAT(_citrus_LC_TIME_, name)
71 #include "nb_lc_time_misc.h"
72 #include "citrus_lc_template_decl.h"
74 static __inline void
75 _citrus_LC_TIME_uninit(_TimeLocale *data)
77 size_t i, j;
79 _DIAGASSERT(data != NULL);
81 for (i = ABDAY_IDX(ABDAY_1), j = ABDAY_IDX(ABDAY_7); i <= j; ++i)
82 free(__UNCONST(data->abday[i]));
83 for (i = DAY_IDX(DAY_1), j = DAY_IDX(DAY_7); i <= j; ++i)
84 free(__UNCONST(data->day[i]));
85 for (i = ABMON_IDX(ABMON_1), j = ABMON_IDX(ABMON_12); i <= j; ++i)
86 free(__UNCONST(data->abmon[i]));
87 for (i = MON_IDX(MON_1), j = MON_IDX(MON_12); i <= j; ++i)
88 free(__UNCONST(data->mon[i]));
89 for (i = AM_PM_IDX(AM_STR), j = AM_PM_IDX(PM_STR); i <= j; ++i)
90 free(__UNCONST(data->am_pm[i]));
91 free(__UNCONST(data->d_t_fmt));
92 free(__UNCONST(data->d_fmt));
93 free(__UNCONST(data->t_fmt));
94 free(__UNCONST(data->t_fmt_ampm));
97 #include "citrus_lc_time.h"
99 struct _citrus_LC_TIME_key {
100 const char *name;
101 size_t offset;
104 #define OFFSET(field) offsetof(_TimeLocale, field)
105 static const struct _citrus_LC_TIME_key keys[] = {
106 { _CITRUS_LC_TIME_SYM_ABDAY_1, OFFSET(abday[ABDAY_IDX(ABDAY_1)] ) },
107 { _CITRUS_LC_TIME_SYM_ABDAY_2, OFFSET(abday[ABDAY_IDX(ABDAY_2)] ) },
108 { _CITRUS_LC_TIME_SYM_ABDAY_3, OFFSET(abday[ABDAY_IDX(ABDAY_3)] ) },
109 { _CITRUS_LC_TIME_SYM_ABDAY_4, OFFSET(abday[ABDAY_IDX(ABDAY_4)] ) },
110 { _CITRUS_LC_TIME_SYM_ABDAY_5, OFFSET(abday[ABDAY_IDX(ABDAY_5)] ) },
111 { _CITRUS_LC_TIME_SYM_ABDAY_6, OFFSET(abday[ABDAY_IDX(ABDAY_6)] ) },
112 { _CITRUS_LC_TIME_SYM_ABDAY_7, OFFSET(abday[ABDAY_IDX(ABDAY_7)] ) },
113 { _CITRUS_LC_TIME_SYM_DAY_1, OFFSET(day[DAY_IDX(DAY_1)] ) },
114 { _CITRUS_LC_TIME_SYM_DAY_2, OFFSET(day[DAY_IDX(DAY_2)] ) },
115 { _CITRUS_LC_TIME_SYM_DAY_3, OFFSET(day[DAY_IDX(DAY_3)] ) },
116 { _CITRUS_LC_TIME_SYM_DAY_4, OFFSET(day[DAY_IDX(DAY_4)] ) },
117 { _CITRUS_LC_TIME_SYM_DAY_5, OFFSET(day[DAY_IDX(DAY_5)] ) },
118 { _CITRUS_LC_TIME_SYM_DAY_6, OFFSET(day[DAY_IDX(DAY_6)] ) },
119 { _CITRUS_LC_TIME_SYM_DAY_7, OFFSET(day[DAY_IDX(DAY_7)] ) },
120 { _CITRUS_LC_TIME_SYM_ABMON_1, OFFSET(abmon[ABMON_IDX(ABMON_1)] ) },
121 { _CITRUS_LC_TIME_SYM_ABMON_2, OFFSET(abmon[ABMON_IDX(ABMON_2)] ) },
122 { _CITRUS_LC_TIME_SYM_ABMON_3, OFFSET(abmon[ABMON_IDX(ABMON_3)] ) },
123 { _CITRUS_LC_TIME_SYM_ABMON_4, OFFSET(abmon[ABMON_IDX(ABMON_4)] ) },
124 { _CITRUS_LC_TIME_SYM_ABMON_5, OFFSET(abmon[ABMON_IDX(ABMON_5)] ) },
125 { _CITRUS_LC_TIME_SYM_ABMON_6, OFFSET(abmon[ABMON_IDX(ABMON_6)] ) },
126 { _CITRUS_LC_TIME_SYM_ABMON_7, OFFSET(abmon[ABMON_IDX(ABMON_7)] ) },
127 { _CITRUS_LC_TIME_SYM_ABMON_8, OFFSET(abmon[ABMON_IDX(ABMON_8)] ) },
128 { _CITRUS_LC_TIME_SYM_ABMON_9, OFFSET(abmon[ABMON_IDX(ABMON_9)] ) },
129 { _CITRUS_LC_TIME_SYM_ABMON_10, OFFSET(abmon[ABMON_IDX(ABMON_10)]) },
130 { _CITRUS_LC_TIME_SYM_ABMON_11, OFFSET(abmon[ABMON_IDX(ABMON_11)]) },
131 { _CITRUS_LC_TIME_SYM_ABMON_12, OFFSET(abmon[ABMON_IDX(ABMON_12)]) },
132 { _CITRUS_LC_TIME_SYM_MON_1, OFFSET(mon[MON_IDX(MON_1)] ) },
133 { _CITRUS_LC_TIME_SYM_MON_2, OFFSET(mon[MON_IDX(MON_2)] ) },
134 { _CITRUS_LC_TIME_SYM_MON_3, OFFSET(mon[MON_IDX(MON_3)] ) },
135 { _CITRUS_LC_TIME_SYM_MON_4, OFFSET(mon[MON_IDX(MON_4)] ) },
136 { _CITRUS_LC_TIME_SYM_MON_5, OFFSET(mon[MON_IDX(MON_5)] ) },
137 { _CITRUS_LC_TIME_SYM_MON_6, OFFSET(mon[MON_IDX(MON_6)] ) },
138 { _CITRUS_LC_TIME_SYM_MON_7, OFFSET(mon[MON_IDX(MON_7)] ) },
139 { _CITRUS_LC_TIME_SYM_MON_8, OFFSET(mon[MON_IDX(MON_8)] ) },
140 { _CITRUS_LC_TIME_SYM_MON_9, OFFSET(mon[MON_IDX(MON_9)] ) },
141 { _CITRUS_LC_TIME_SYM_MON_10, OFFSET(mon[MON_IDX(MON_10)] ) },
142 { _CITRUS_LC_TIME_SYM_MON_11, OFFSET(mon[MON_IDX(MON_11)] ) },
143 { _CITRUS_LC_TIME_SYM_MON_12, OFFSET(mon[MON_IDX(MON_12)] ) },
144 { _CITRUS_LC_TIME_SYM_AM_STR, OFFSET(am_pm[AM_PM_IDX(AM_STR)] ) },
145 { _CITRUS_LC_TIME_SYM_PM_STR, OFFSET(am_pm[AM_PM_IDX(PM_STR)] ) },
146 { _CITRUS_LC_TIME_SYM_D_T_FMT, OFFSET(d_t_fmt ) },
147 { _CITRUS_LC_TIME_SYM_D_FMT, OFFSET(d_fmt ) },
148 { _CITRUS_LC_TIME_SYM_T_FMT, OFFSET(t_fmt ) },
149 { _CITRUS_LC_TIME_SYM_T_FMT_AMPM, OFFSET(t_fmt_ampm ) },
150 { NULL, 0 }
153 static __inline int
154 _citrus_LC_TIME_init_normal(_TimeLocale * __restrict data,
155 struct _citrus_db * __restrict db)
157 const struct _citrus_LC_TIME_key *key;
158 char **p;
159 const char *s;
161 _DIAGASSERT(data != NULL);
162 _DIAGASSERT(db != NULL);
164 memset(data, 0, sizeof(*data));
165 for (key = &keys[0]; key->name != NULL; ++key) {
166 if (_db_lookupstr_by_s(db, key->name, &s, NULL))
167 goto fatal;
168 p = (char **)(void *)
169 (((char *)(void *)data) + key->offset);
170 *p = strdup(s);
171 if (*p == NULL)
172 goto fatal;
174 return 0;
176 fatal:
177 _citrus_LC_TIME_uninit(data);
178 return EFTYPE;
181 static __inline int
182 _citrus_LC_TIME_init_fallback(_TimeLocale * __restrict data,
183 struct _memstream * __restrict ms)
185 const struct _citrus_LC_TIME_key *key;
186 char **p;
187 const char *s;
188 size_t n;
190 memset(data, 0, sizeof(*data));
191 for (key = &keys[0]; key->name != NULL; ++key) {
192 if ((s = _memstream_getln(ms, &n)) == NULL)
193 goto fatal;
194 p = (char **)(void *)
195 (((char *)(void *)data) + key->offset);
196 *p = strndup(s, n - 1);
197 if (*p == NULL)
198 goto fatal;
200 return 0;
202 fatal:
203 _citrus_LC_TIME_uninit(data);
204 return EFTYPE;
208 * macro required by citrus_lc_template.h
210 #define _CATEGORY_DB "LC_TIME"
211 #define _CATEGORY_MAGIC _CITRUS_LC_TIME_MAGIC_1
213 #include "citrus_lc_template.h"