1 --- lmessages.c.orig 2004-11-25 11:38:17.000000000 -0800
2 +++ lmessages.c 2005-02-17 10:13:34.000000000 -0800
5 __FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.14 2003/06/26 10:46:16 phantom Exp $");
7 +#include "xlocale_private.h"
13 #include "lmessages.h"
18 -static struct lc_messages_T _messages_locale;
19 -static int _messages_using_locale;
20 -static char *_messages_locale_buf;
23 -__messages_load_locale(const char *name)
24 +__private_extern__ int
25 +__messages_load_locale(const char *name, locale_t loc)
28 + struct __xlocale_st_messages *xp;
29 + static struct __xlocale_st_messages *cache = NULL;
31 + /* 'name' must be already checked. */
32 + if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0) {
33 + loc->_messages_using_locale = 0;
34 + XL_RELEASE(loc->__lc_messages);
35 + loc->__lc_messages = NULL;
36 + return (_LDP_CACHE);
39 - ret = __part_load_locale(name, &_messages_using_locale,
40 - &_messages_locale_buf, "LC_MESSAGES",
42 + * If the locale name is the same as our cache, use the cache.
44 + if (cache && cache->_messages_locale_buf && strcmp(name, cache->_messages_locale_buf) == 0) {
45 + loc->_messages_using_locale = 1;
46 + XL_RELEASE(loc->__lc_messages);
47 + loc->__lc_messages = cache;
48 + XL_RETAIN(loc->__lc_messages);
49 + return (_LDP_CACHE);
51 + if ((xp = (struct __xlocale_st_messages *)malloc(sizeof(*xp))) == NULL)
54 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
55 + xp->_messages_locale_buf = NULL;
57 + ret = __part_load_locale(name, &loc->_messages_using_locale,
58 + &xp->_messages_locale_buf, "LC_MESSAGES/LC_MESSAGES",
59 LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
60 - (const char **)&_messages_locale);
61 + (const char **)&xp->_messages_locale);
62 if (ret == _LDP_LOADED) {
63 - if (_messages_locale.yesstr == NULL)
64 - _messages_locale.yesstr = empty;
65 - if (_messages_locale.nostr == NULL)
66 - _messages_locale.nostr = empty;
68 + if (xp->_messages_locale.yesstr == NULL)
69 + xp->_messages_locale.yesstr = empty;
70 + if (xp->_messages_locale.nostr == NULL)
71 + xp->_messages_locale.nostr = empty;
72 + XL_RELEASE(loc->__lc_messages);
73 + loc->__lc_messages = xp;
77 + } else if (ret == _LDP_ERROR)
82 -struct lc_messages_T *
83 -__get_current_messages_locale(void)
84 +__private_extern__ struct lc_messages_T *
85 +__get_current_messages_locale(locale_t loc)
87 - return (_messages_using_locale
89 + return (loc->_messages_using_locale
90 + ? &loc->__lc_messages->_messages_locale
91 : (struct lc_messages_T *)&_C_messages_locale);
97 +locale_t loc = __current_locale();
98 printf( "yesexpr = %s\n"
102 - _messages_locale.yesexpr,
103 - _messages_locale.noexpr,
104 - _messages_locale.yesstr,
105 - _messages_locale.nostr
106 + loc->__lc_messages->_messages_locale.yesexpr,
107 + loc->__lc_messages->_messages_locale.noexpr,
108 + loc->__lc_messages->_messages_locale.yesstr,
109 + loc->__lc_messages->_messages_locale.nostr
112 #endif /* LOCALE_DEBUG */