4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Copyright 2015 Joyent, Inc.
30 #pragma weak _bindtextdomain = bindtextdomain
31 #pragma weak _textdomain = textdomain
32 #pragma weak _gettext = gettext
33 #pragma weak _dgettext = dgettext
34 #pragma weak _dcgettext = dcgettext
35 #pragma weak _ngettext = ngettext
36 #pragma weak _dngettext = dngettext
37 #pragma weak _dcngettext = dcngettext
38 #pragma weak _bind_textdomain_codeset = bind_textdomain_codeset
47 #include <sys/types.h>
48 #include <sys/param.h>
53 #include "_loc_path.h"
57 #define INIT_GT(def) \
59 global_gt = (Gettext_t *)calloc(1, sizeof (Gettext_t)); \
61 global_gt->cur_domain = (char *)default_domain; \
63 callout_lock_exit(); \
68 const char *defaultbind
= DEFAULT_BINDING
;
69 const char default_domain
[] = DEFAULT_DOMAIN
;
70 Gettext_t
*global_gt
= NULL
;
73 bindtextdomain(const char *domain
, const char *binding
)
79 res
= _real_bindtextdomain_u(domain
, binding
, TP_BINDING
);
85 bind_textdomain_codeset(const char *domain
, const char *codeset
)
91 res
= _real_bindtextdomain_u(domain
, codeset
, TP_CODESET
);
97 * textdomain() sets or queries the name of the current domain of
98 * the active LC_MESSAGES locale category.
101 textdomain(const char *domain
)
104 char tmp_domain
[TEXTDOMAINMAX
+ 1];
106 callout_lock_enter();
108 res
= _textdomain_u(domain
, tmp_domain
);
114 return (CURRENT_DOMAIN(global_gt
));
118 * gettext() is a pass-thru to _real_gettext_u() with a NULL pointer passed
119 * for domain and LC_MESSAGES passed for category.
122 gettext(const char *msg_id
)
125 int errno_save
= errno
;
127 callout_lock_enter();
128 INIT_GT((char *)msg_id
);
129 res
= _real_gettext_u(NULL
, msg_id
, NULL
, 0, LC_MESSAGES
, 0, NULL
);
137 * In dcgettext() call, domain is valid only for this call.
140 dgettext(const char *domain
, const char *msg_id
)
143 int errno_save
= errno
;
145 callout_lock_enter();
146 INIT_GT((char *)msg_id
);
147 res
= _real_gettext_u(domain
, msg_id
, NULL
, 0, LC_MESSAGES
, 0, NULL
);
154 dgettext_l(const char *domain
, const char *msg_id
, locale_t loc
)
157 int errno_save
= errno
;
159 callout_lock_enter();
160 INIT_GT((char *)msg_id
);
161 res
= _real_gettext_u(domain
, msg_id
, NULL
, 0, LC_MESSAGES
, 0, loc
);
168 dcgettext(const char *domain
, const char *msg_id
, const int category
)
171 int errno_save
= errno
;
173 callout_lock_enter();
174 INIT_GT((char *)msg_id
);
175 res
= _real_gettext_u(domain
, msg_id
, NULL
, 0, category
, 0, NULL
);
182 ngettext(const char *msgid1
, const char *msgid2
, unsigned long int n
)
185 int errno_save
= errno
;
187 callout_lock_enter();
188 INIT_GT((char *)msgid1
);
189 res
= _real_gettext_u(NULL
, msgid1
, msgid2
, n
, LC_MESSAGES
, 1, NULL
);
196 dngettext(const char *domain
, const char *msgid1
, const char *msgid2
,
200 int errno_save
= errno
;
202 callout_lock_enter();
203 INIT_GT((char *)msgid1
);
204 res
= _real_gettext_u(domain
, msgid1
, msgid2
, n
, LC_MESSAGES
, 1, NULL
);
211 dcngettext(const char *domain
, const char *msgid1
, const char *msgid2
,
212 unsigned long int n
, int category
)
215 int errno_save
= errno
;
217 callout_lock_enter();
218 INIT_GT((char *)msgid1
);
219 res
= _real_gettext_u(domain
, msgid1
, msgid2
, n
, category
, 1, NULL
);