1 --- timelocal.c.orig 2004-11-25 11:38:45.000000000 -0800
2 +++ timelocal.c 2005-02-17 10:08:04.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $");
7 +#include "xlocale_private.h"
13 #include "timelocal.h"
15 -static struct lc_time_T _time_locale;
16 -static int _time_using_locale;
17 -static char *time_locale_buf;
19 #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
21 static const struct lc_time_T _C_time_locale = {
27 -__get_current_time_locale(void)
28 +__private_extern__ struct lc_time_T *
29 +__get_current_time_locale(locale_t loc)
31 - return (_time_using_locale
33 + return (loc->_time_using_locale
34 + ? &loc->__lc_time->_time_locale
35 : (struct lc_time_T *)&_C_time_locale);
39 -__time_load_locale(const char *name)
40 +__private_extern__ int
41 +__time_load_locale(const char *name, locale_t loc)
43 - return (__part_load_locale(name, &_time_using_locale,
44 - &time_locale_buf, "LC_TIME",
46 + struct __xlocale_st_time *xp;
47 + static struct __xlocale_st_time *cache = NULL;
49 + /* 'name' must be already checked. */
50 + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
51 + loc->_time_using_locale = 0;
52 + XL_RELEASE(loc->__lc_time);
53 + loc->__lc_time = NULL;
54 + return (_LDP_CACHE);
58 + * If the locale name is the same as our cache, use the cache.
60 + if (cache && cache->_time_locale_buf && strcmp(name, cache->_time_locale_buf) == 0) {
61 + loc->_time_using_locale = 1;
62 + XL_RELEASE(loc->__lc_time);
63 + loc->__lc_time = cache;
64 + XL_RETAIN(loc->__lc_time);
65 + return (_LDP_CACHE);
67 + if ((xp = (struct __xlocale_st_time *)malloc(sizeof(*xp))) == NULL)
70 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
71 + xp->_time_locale_buf = NULL;
73 + ret = __part_load_locale(name, &loc->_time_using_locale,
74 + &xp->_time_locale_buf, "LC_TIME",
75 LCTIME_SIZE, LCTIME_SIZE,
76 - (const char **)&_time_locale));
77 + (const char **)&xp->_time_locale);
78 + if (ret == _LDP_LOADED) {
79 + XL_RELEASE(loc->__lc_time);
80 + loc->__lc_time = xp;
84 + } else if (ret == _LDP_ERROR)