annotate intl/bindtextdom.c @ 262:5410de731c3c trunk

[svn] Remove last of the internal OSS support and default to ALSA. Squashed a few warnings but it is still messy.
author chainsaw
date Wed, 07 Dec 2005 15:37:52 -0800
parents cb178e5ad177
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Implementation of the bindtextdomain(3) function
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 License along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 # include <config.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include <stddef.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 # include <libintl.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 # include "libgnuintl.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include "gettextP.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 /* We have to handle multi-threaded applications. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 # include <bits/libc-lock.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 /* Provide dummy implementation if this is outside glibc. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 # define __libc_rwlock_define(CLASS, NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 # define __libc_rwlock_wrlock(NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 # define __libc_rwlock_unlock(NAME)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 /* The internal variables in the standalone libintl.a must have different
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 names than the internal variables in GNU libc, otherwise programs
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 using libintl.a cannot be linked statically. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 #if !defined _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 # define _nl_default_dirname libintl_nl_default_dirname
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 # define _nl_domain_bindings libintl_nl_domain_bindings
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 /* Some compilers, like SunOS4 cc, don't have offsetof in <stddef.h>. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #ifndef offsetof
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 # define offsetof(type,ident) ((size_t)&(((type*)0)->ident))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 /* @@ end of prolog @@ */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 /* Contains the default location of the message catalogs. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 extern const char _nl_default_dirname[];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 extern const char _nl_default_dirname_internal[] attribute_hidden;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 # define INTUSE(name) name
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 /* List with bindings of specific domains. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 extern struct binding *_nl_domain_bindings;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 /* Lock variable to protect the global data in the gettext implementation. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 __libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 /* Names for the libintl functions are a problem. They must not clash
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 with existing names and they should follow ANSI C. But this source
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 code is also used in GNU C Library where the names have a __
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 prefix. So we have to make a difference here. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 # define BINDTEXTDOMAIN __bindtextdomain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 # define BIND_TEXTDOMAIN_CODESET __bind_textdomain_codeset
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 # ifndef strdup
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 # define strdup(str) __strdup (str)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 # endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 # define BINDTEXTDOMAIN libintl_bindtextdomain
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 # define BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 /* Prototypes for local functions. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 static void set_binding_values PARAMS ((const char *domainname,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 const char **dirnamep,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 const char **codesetp));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 /* Specifies the directory name *DIRNAMEP and the output codeset *CODESETP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 to be used for the DOMAINNAME message catalog.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 If *DIRNAMEP or *CODESETP is NULL, the corresponding attribute is not
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 modified, only the current value is returned.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 If DIRNAMEP or CODESETP is NULL, the corresponding attribute is neither
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 modified nor returned. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 set_binding_values (domainname, dirnamep, codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 const char *domainname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 const char **dirnamep;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 const char **codesetp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 struct binding *binding;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 int modified;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 /* Some sanity checks. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 if (domainname == NULL || domainname[0] == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 if (dirnamep)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 *dirnamep = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 if (codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 *codesetp = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 __libc_rwlock_wrlock (_nl_state_lock);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 modified = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 int compare = strcmp (domainname, binding->domainname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 if (compare == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 /* We found it! */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 if (compare < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 /* It is not in the list. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 binding = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 if (binding != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if (dirnamep)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 const char *dirname = *dirnamep;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 if (dirname == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 /* The current binding has be to returned. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 *dirnamep = binding->dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 /* The domain is already bound. If the new value and the old
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 one are equal we simply do nothing. Otherwise replace the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 old binding. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 char *result = binding->dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 if (strcmp (dirname, result) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 result = (char *) INTUSE(_nl_default_dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 result = strdup (dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 size_t len = strlen (dirname) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 result = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 if (__builtin_expect (result != NULL, 1))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 memcpy (result, dirname, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 if (__builtin_expect (result != NULL, 1))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 if (binding->dirname != INTUSE(_nl_default_dirname))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 free (binding->dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 binding->dirname = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 modified = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 *dirnamep = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 if (codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 const char *codeset = *codesetp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 if (codeset == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 /* The current binding has be to returned. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 *codesetp = binding->codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 /* The domain is already bound. If the new value and the old
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 one are equal we simply do nothing. Otherwise replace the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 old binding. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 char *result = binding->codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 if (result == NULL || strcmp (codeset, result) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 result = strdup (codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 size_t len = strlen (codeset) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 result = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 if (__builtin_expect (result != NULL, 1))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 memcpy (result, codeset, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 if (__builtin_expect (result != NULL, 1))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 if (binding->codeset != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 free (binding->codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 binding->codeset = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 binding->codeset_cntr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 modified = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 *codesetp = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 else if ((dirnamep == NULL || *dirnamep == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 && (codesetp == NULL || *codesetp == NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 /* Simply return the default values. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 if (dirnamep)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 *dirnamep = INTUSE(_nl_default_dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 if (codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 *codesetp = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 /* We have to create a new binding. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 size_t len = strlen (domainname) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 struct binding *new_binding =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 (struct binding *) malloc (offsetof (struct binding, domainname) + len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 if (__builtin_expect (new_binding == NULL, 0))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 goto failed;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 memcpy (new_binding->domainname, domainname, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 if (dirnamep)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 const char *dirname = *dirnamep;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 if (dirname == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 /* The default value. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 dirname = INTUSE(_nl_default_dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 dirname = INTUSE(_nl_default_dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 char *result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 result = strdup (dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 if (__builtin_expect (result == NULL, 0))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 goto failed_dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 size_t len = strlen (dirname) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 result = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 if (__builtin_expect (result == NULL, 0))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 goto failed_dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 memcpy (result, dirname, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 dirname = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 *dirnamep = dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 new_binding->dirname = (char *) dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 /* The default value. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 new_binding->dirname = (char *) INTUSE(_nl_default_dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 new_binding->codeset_cntr = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 if (codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 const char *codeset = *codesetp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 if (codeset != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 char *result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 #if defined _LIBC || defined HAVE_STRDUP
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 result = strdup (codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 if (__builtin_expect (result == NULL, 0))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 goto failed_codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 size_t len = strlen (codeset) + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 result = (char *) malloc (len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 if (__builtin_expect (result == NULL, 0))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 goto failed_codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 memcpy (result, codeset, len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 codeset = result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 new_binding->codeset_cntr++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 *codesetp = codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 new_binding->codeset = (char *) codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 new_binding->codeset = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 /* Now enqueue it. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 if (_nl_domain_bindings == NULL
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 || strcmp (domainname, _nl_domain_bindings->domainname) < 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 new_binding->next = _nl_domain_bindings;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 _nl_domain_bindings = new_binding;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 binding = _nl_domain_bindings;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 while (binding->next != NULL
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 && strcmp (domainname, binding->next->domainname) > 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 binding = binding->next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 new_binding->next = binding->next;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 binding->next = new_binding;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 modified = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 /* Here we deal with memory allocation failures. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 if (0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 failed_codeset:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 if (new_binding->dirname != INTUSE(_nl_default_dirname))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 free (new_binding->dirname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 failed_dirname:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 free (new_binding);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 failed:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 if (dirnamep)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 *dirnamep = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 if (codesetp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 *codesetp = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 /* If we modified any binding, we flush the caches. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 if (modified)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 ++_nl_msg_cat_cntr;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 __libc_rwlock_unlock (_nl_state_lock);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 /* Specify that the DOMAINNAME message catalog will be found
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 in DIRNAME rather than in the system locale data base. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 BINDTEXTDOMAIN (domainname, dirname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 const char *domainname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 const char *dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 set_binding_values (domainname, &dirname, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 return (char *) dirname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 /* Specify the character encoding in which the messages from the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 DOMAINNAME message catalog will be returned. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 BIND_TEXTDOMAIN_CODESET (domainname, codeset)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 const char *domainname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 const char *codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 set_binding_values (domainname, NULL, &codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 return (char *) codeset;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 #ifdef _LIBC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 /* Aliases for function names in GNU C Library. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 weak_alias (__bindtextdomain, bindtextdomain);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 weak_alias (__bind_textdomain_codeset, bind_textdomain_codeset);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 #endif