Print this page
2964 need POSIX 2008 locale object support
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/port/locale/lmessages.c
+++ new/usr/src/lib/libc/port/locale/lmessages.c
1 1 /*
2 2 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
3 3 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
4 4 * All rights reserved.
5 5 *
6 + * Copyright (c) 2011 The FreeBSD Foundation
7 + * All rights reserved.
8 + * Portions of this software were developed by David Chisnall
9 + * under sponsorship from the FreeBSD Foundation.
10 + *
6 11 * Redistribution and use in source and binary forms, with or without
7 12 * modification, are permitted provided that the following conditions
8 13 * are met:
9 14 * 1. Redistributions of source code must retain the above copyright
10 15 * notice, this list of conditions and the following disclaimer.
11 16 * 2. Redistributions in binary form must reproduce the above copyright
12 17 * notice, this list of conditions and the following disclaimer in the
13 18 * documentation and/or other materials provided with the distribution.
14 19 *
15 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
20 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 30 * SUCH DAMAGE.
26 31 */
27 32
28 33 #include "lint.h"
29 34 #include <stddef.h>
35 +#include <stdlib.h>
30 36 #include "ldpart.h"
31 37 #include "lmessages.h"
32 38
33 39 #define LCMESSAGES_SIZE_FULL (sizeof (struct lc_messages_T) / sizeof (char *))
34 40 #define LCMESSAGES_SIZE_MIN \
35 41 (offsetof(struct lc_messages_T, yesstr) / sizeof (char *))
36 42
43 +struct xlocale_messages __xlocale_global_messages;
44 +
37 45 static char empty[] = "";
38 46
39 47 static const struct lc_messages_T _C_messages_locale = {
40 48 "^[yY]", /* yesexpr */
41 49 "^[nN]", /* noexpr */
42 50 "yes", /* yesstr */
43 51 "no" /* nostr */
44 52 };
45 53
46 -static struct lc_messages_T _messages_locale;
47 -static int _messages_using_locale;
48 -static char *_messages_locale_buf;
54 +static void
55 +destruct_messages(void *v)
56 +{
57 + struct xlocale_messages *l = v;
49 58
50 -int
51 -__messages_load_locale(const char *name)
59 + if (l->buffer != NULL)
60 + free(l->buffer);
61 +
62 + free(l);
63 +}
64 +
65 +static int
66 +messages_load_locale(struct xlocale_messages *loc, int *using_locale,
67 + const char *name)
52 68 {
53 69 int ret;
70 + struct lc_messages_T *l = &loc->locale;
54 71
55 - ret = __part_load_locale(name, &_messages_using_locale,
56 - &_messages_locale_buf, "LC_MESSAGES",
72 + ret = __part_load_locale(name, using_locale,
73 + &loc->buffer, "LC_MESSAGES",
57 74 LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
58 - (const char **)&_messages_locale);
75 + (const char **)l);
59 76 if (ret == _LDP_LOADED) {
60 - if (_messages_locale.yesstr == NULL)
61 - _messages_locale.yesstr = empty;
62 - if (_messages_locale.nostr == NULL)
63 - _messages_locale.nostr = empty;
77 + if (l->yesstr == NULL)
78 + l->yesstr = empty;
79 + if (l->nostr == NULL)
80 + l->nostr = empty;
64 81 }
82 +
65 83 return (ret);
66 84 }
67 85
86 +int
87 +__messages_load_locale(const char *name)
88 +{
89 + return (messages_load_locale(&__xlocale_global_messages,
90 + &__xlocale_global_locale.using_messages_locale, name));
91 +}
92 +
93 +void *
94 +__messages_load(const char *name, locale_t l)
95 +{
96 + struct xlocale_messages *new;
97 +
98 + new = calloc(sizeof(struct xlocale_messages), 1);
99 + /* XXX */
100 + new->header.header.destructor = destruct_messages;
101 + if (messages_load_locale(new, &l->using_messages_locale, name) ==
102 + _LDP_ERROR) {
103 + xlocale_release(new);
104 + return (NULL);
105 + }
106 +
107 + return (new);
108 +}
109 +
68 110 struct lc_messages_T *
69 -__get_current_messages_locale(void)
111 +__get_current_messages_locale(locale_t loc)
70 112 {
71 - return (_messages_using_locale ? &_messages_locale :
72 - (struct lc_messages_T *)&_C_messages_locale);
113 + return (loc->using_messages_locale
114 + ? &((struct xlocale_messages *)loc->components[XLC_MESSAGES])->locale
115 + : (struct lc_messages_T *)&_C_messages_locale);
73 116 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX