2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3 * Copyright (c) 1997 FreeBSD Inc.
6 * Copyright (c) 2011 The FreeBSD Foundation
8 * Portions of this software were developed by David Chisnall
9 * under sponsorship from the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
39 #include "timelocal.h"
42 struct xlocale_component header;
44 struct lc_time_T locale;
47 struct xlocale_time __xlocale_global_time;
49 #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
51 static const struct lc_time_T _C_time_locale = {
53 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
54 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
56 "January", "February", "March", "April", "May", "June",
57 "July", "August", "September", "October", "November", "December"
59 "Sun", "Mon", "Tue", "Wed",
62 "Sunday", "Monday", "Tuesday", "Wednesday",
63 "Thursday", "Friday", "Saturday"
71 * Since the C language standard calls for
72 * "date, using locale's date format," anything goes.
73 * Using just numbers (as here) makes Quakers happier;
74 * it's also compatible with SVR4.
81 "%a %b %e %H:%M:%S %Y",
90 "%a %b %e %H:%M:%S %Z %Y",
93 * Standalone months forms for %OB
96 "January", "February", "March", "April", "May", "June",
97 "July", "August", "September", "October", "November", "December"
101 * Month / day order in dates
106 * To determine 12-hour clock format time (empty, if N/A)
111 static void destruct_time(void *v)
113 struct xlocale_time *l = v;
121 __get_current_time_locale(locale_t loc)
123 return (loc->using_time_locale
124 ? &((struct xlocale_time *)loc->components[XLC_TIME])->locale
125 : (struct lc_time_T *)&_C_time_locale);
129 time_load_locale(struct xlocale_time *l, int *using_locale, const char *name)
131 struct lc_time_T *time_locale = &l->locale;
132 return (__part_load_locale(name, using_locale,
133 &l->buffer, "LC_TIME",
134 LCTIME_SIZE, LCTIME_SIZE,
135 (const char **)time_locale));
138 __time_load_locale(const char *name)
140 return time_load_locale(&__xlocale_global_time,
141 &__xlocale_global_locale.using_time_locale, name);
143 void* __time_load(const char* name, locale_t loc)
145 struct xlocale_time *new = calloc(sizeof(struct xlocale_time), 1);
146 new->header.header.destructor = destruct_time;
147 if (time_load_locale(new, &loc->using_time_locale, name) == _LDP_ERROR)
149 xlocale_release(new);