]>
git.saurik.com Git - apple/libc.git/blob - stdtime/timelocal-fbsd.c
2 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3 * Copyright (c) 1997 FreeBSD Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $");
31 #include "xlocale_private.h"
37 #include "timelocal.h"
39 #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
41 static const struct lc_time_T _C_time_locale
= {
43 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
44 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
46 "January", "February", "March", "April", "May", "June",
47 "July", "August", "September", "October", "November", "December"
49 "Sun", "Mon", "Tue", "Wed",
52 "Sunday", "Monday", "Tuesday", "Wednesday",
53 "Thursday", "Friday", "Saturday"
61 * Since the C language standard calls for
62 * "date, using locale's date format," anything goes.
63 * Using just numbers (as here) makes Quakers happier;
64 * it's also compatible with SVR4.
71 "%a %b %e %H:%M:%S %Y",
80 "%a %b %e %H:%M:%S %Z %Y",
83 * Standalone months forms for %OB
86 "January", "February", "March", "April", "May", "June",
87 "July", "August", "September", "October", "November", "December"
91 * Month / day order in dates
96 * To determine 12-hour clock format time (empty, if N/A)
101 __private_extern__
struct lc_time_T
*
102 __get_current_time_locale(locale_t loc
)
104 return (loc
->_time_using_locale
105 ? &loc
->__lc_time
->_time_locale
106 : (struct lc_time_T
*)&_C_time_locale
);
109 __private_extern__
int
110 __time_load_locale(const char *name
, locale_t loc
)
113 struct __xlocale_st_time
*xp
;
114 static struct __xlocale_st_time
*cache
= NULL
;
116 /* 'name' must be already checked. */
117 if (strcmp(name
, "C") == 0 || strcmp(name
, "POSIX") == 0) {
118 loc
->_time_using_locale
= 0;
119 XL_RELEASE(loc
->__lc_time
);
120 loc
->__lc_time
= NULL
;
125 * If the locale name is the same as our cache, use the cache.
127 if (cache
&& cache
->_time_locale_buf
&& strcmp(name
, cache
->_time_locale_buf
) == 0) {
128 loc
->_time_using_locale
= 1;
129 XL_RELEASE(loc
->__lc_time
);
130 loc
->__lc_time
= cache
;
131 XL_RETAIN(loc
->__lc_time
);
134 if ((xp
= (struct __xlocale_st_time
*)malloc(sizeof(*xp
))) == NULL
)
137 xp
->__free_extra
= (__free_extra_t
)__ldpart_free_extra
;
138 xp
->_time_locale_buf
= NULL
;
140 ret
= __part_load_locale(name
, &loc
->_time_using_locale
,
141 &xp
->_time_locale_buf
, "LC_TIME",
142 LCTIME_SIZE
, LCTIME_SIZE
,
143 (const char **)&xp
->_time_locale
);
144 if (ret
== _LDP_LOADED
) {
145 XL_RELEASE(loc
->__lc_time
);
150 } else if (ret
== _LDP_ERROR
)