]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- timelocal.c.orig 2004-11-25 11:38:45.000000000 -0800 |
2 | +++ timelocal.c 2005-02-17 10:08:04.000000000 -0800 | |
3 | @@ -28,15 +28,14 @@ | |
4 | #include <sys/cdefs.h> | |
5 | __FBSDID("$FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.25 2003/06/13 00:14:07 jkh Exp $"); | |
6 | ||
7 | +#include "xlocale_private.h" | |
8 | + | |
9 | #include <stddef.h> | |
10 | +#include <string.h> | |
11 | ||
12 | #include "ldpart.h" | |
13 | #include "timelocal.h" | |
14 | ||
15 | -static struct lc_time_T _time_locale; | |
16 | -static int _time_using_locale; | |
17 | -static char *time_locale_buf; | |
18 | - | |
19 | #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) | |
20 | ||
21 | static const struct lc_time_T _C_time_locale = { | |
22 | @@ -99,19 +98,57 @@ | |
23 | "%I:%M:%S %p" | |
24 | }; | |
25 | ||
26 | -struct lc_time_T * | |
27 | -__get_current_time_locale(void) | |
28 | +__private_extern__ struct lc_time_T * | |
29 | +__get_current_time_locale(locale_t loc) | |
9385eb3d | 30 | { |
3d9156a7 A |
31 | - return (_time_using_locale |
32 | - ? &_time_locale | |
33 | + return (loc->_time_using_locale | |
34 | + ? &loc->__lc_time->_time_locale | |
35 | : (struct lc_time_T *)&_C_time_locale); | |
36 | } | |
37 | ||
38 | -int | |
39 | -__time_load_locale(const char *name) | |
40 | +__private_extern__ int | |
41 | +__time_load_locale(const char *name, locale_t loc) | |
42 | { | |
43 | - return (__part_load_locale(name, &_time_using_locale, | |
44 | - &time_locale_buf, "LC_TIME", | |
45 | + int ret; | |
46 | + struct __xlocale_st_time *xp; | |
47 | + static struct __xlocale_st_time *cache = NULL; | |
48 | + | |
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); | |
55 | + } | |
56 | + | |
57 | + /* | |
58 | + * If the locale name is the same as our cache, use the cache. | |
59 | + */ | |
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); | |
66 | + } | |
67 | + if ((xp = (struct __xlocale_st_time *)malloc(sizeof(*xp))) == NULL) | |
68 | + return _LDP_ERROR; | |
69 | + xp->__refcount = 1; | |
70 | + xp->__free_extra = (__free_extra_t)__ldpart_free_extra; | |
71 | + xp->_time_locale_buf = NULL; | |
72 | + | |
73 | + ret = __part_load_locale(name, &loc->_time_using_locale, | |
74 | + &xp->_time_locale_buf, "LC_TIME", | |
9385eb3d | 75 | LCTIME_SIZE, LCTIME_SIZE, |
3d9156a7 A |
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; | |
81 | + XL_RELEASE(cache); | |
82 | + cache = xp; | |
83 | + XL_RETAIN(cache); | |
84 | + } else if (ret == _LDP_ERROR) | |
85 | + free(xp); | |
86 | + | |
87 | + return (ret); | |
9385eb3d | 88 | } |