]> git.saurik.com Git - apple/libc.git/blob - locale/FreeBSD/lmessages.c.patch
Libc-391.tar.gz
[apple/libc.git] / locale / FreeBSD / lmessages.c.patch
1 --- lmessages.c.orig 2004-11-25 11:38:17.000000000 -0800
2 +++ lmessages.c 2005-02-17 10:13:34.000000000 -0800
3 @@ -27,7 +27,10 @@
4 #include <sys/cdefs.h>
5 __FBSDID("$FreeBSD: src/lib/libc/locale/lmessages.c,v 1.14 2003/06/26 10:46:16 phantom Exp $");
6
7 +#include "xlocale_private.h"
8 +
9 #include <stddef.h>
10 +#include <string.h>
11
12 #include "ldpart.h"
13 #include "lmessages.h"
14 @@ -45,47 +48,76 @@
15 "no" /* nostr */
16 };
17
18 -static struct lc_messages_T _messages_locale;
19 -static int _messages_using_locale;
20 -static char *_messages_locale_buf;
21 -
22 -int
23 -__messages_load_locale(const char *name)
24 +__private_extern__ int
25 +__messages_load_locale(const char *name, locale_t loc)
26 {
27 int ret;
28 + struct __xlocale_st_messages *xp;
29 + static struct __xlocale_st_messages *cache = NULL;
30 +
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);
37 + }
38
39 - ret = __part_load_locale(name, &_messages_using_locale,
40 - &_messages_locale_buf, "LC_MESSAGES",
41 + /*
42 + * If the locale name is the same as our cache, use the cache.
43 + */
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);
50 + }
51 + if ((xp = (struct __xlocale_st_messages *)malloc(sizeof(*xp))) == NULL)
52 + return _LDP_ERROR;
53 + xp->__refcount = 1;
54 + xp->__free_extra = (__free_extra_t)__ldpart_free_extra;
55 + xp->_messages_locale_buf = NULL;
56 +
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;
67 - }
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;
74 + XL_RELEASE(cache);
75 + cache = xp;
76 + XL_RETAIN(cache);
77 + } else if (ret == _LDP_ERROR)
78 + free(xp);
79 return (ret);
80 }
81
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)
86 {
87 - return (_messages_using_locale
88 - ? &_messages_locale
89 + return (loc->_messages_using_locale
90 + ? &loc->__lc_messages->_messages_locale
91 : (struct lc_messages_T *)&_C_messages_locale);
92 }
93
94 #ifdef LOCALE_DEBUG
95 void
96 msgdebug() {
97 +locale_t loc = __current_locale();
98 printf( "yesexpr = %s\n"
99 "noexpr = %s\n"
100 "yesstr = %s\n"
101 "nostr = %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
110 );
111 }
112 #endif /* LOCALE_DEBUG */