#include <stddef.h>#include <stdlib.h>#include <string.h>#include "libgnuintl.h"#include "gettextP.h"Go to the source code of this file.
Defines | |
| #define | __libc_rwlock_define(CLASS, NAME) |
| #define | __libc_rwlock_wrlock(NAME) |
| #define | __libc_rwlock_unlock(NAME) |
| #define | _nl_default_dirname libintl_nl_default_dirname |
| #define | _nl_domain_bindings libintl_nl_domain_bindings |
| #define | offsetof(type, ident) ((size_t)&(((type*)0)->ident)) |
| #define | INTUSE(name) name |
| #define | BINDTEXTDOMAIN libintl_bindtextdomain |
| #define | BIND_TEXTDOMAIN_CODESET libintl_bind_textdomain_codeset |
Functions | |
| static void | set_binding_values (char *domainname, const char **dirnamep, const char **codesetp) const |
Variables | |
| const char ** | dirnamep |
| const char const char ** | codesetp |
| char *const char * | domainname |
| const char * | dirname |
| const char * | codeset |
|
|
Definition at line 39 of file bindtextdom.c. |
|
|
Definition at line 41 of file bindtextdom.c. Referenced by set_binding_values(). |
|
|
Definition at line 40 of file bindtextdom.c. Referenced by set_binding_values(). |
|
|
Definition at line 48 of file bindtextdom.c. Referenced by set_binding_values(). |
|
|
Definition at line 49 of file bindtextdom.c. |
|
|
|
|
|
|
|
|
Definition at line 64 of file bindtextdom.c. Referenced by set_binding_values(). |
|
|
Definition at line 54 of file bindtextdom.c. Referenced by set_binding_values(). |
|
||||||||||||||||
|
Definition at line 101 of file bindtextdom.c. References __builtin_expect, __libc_rwlock_unlock, __libc_rwlock_wrlock, _nl_default_dirname, _nl_msg_cat_cntr, binding::codeset, codeset, binding::codeset_cntr, binding::dirname, dirname, binding::domainname, free(), INTUSE, len, malloc(), memcpy, binding::next, NULL, offsetof, and strdup. 00105 { 00106 struct binding *binding; 00107 int modified; 00108 00109 /* Some sanity checks. */ 00110 if (domainname == NULL || domainname[0] == '\0') 00111 { 00112 if (dirnamep) 00113 *dirnamep = NULL; 00114 if (codesetp) 00115 *codesetp = NULL; 00116 return; 00117 } 00118 00119 __libc_rwlock_wrlock (_nl_state_lock); 00120 00121 modified = 0; 00122 00123 for (binding = _nl_domain_bindings; binding != NULL; binding = binding->next) 00124 { 00125 int compare = strcmp (domainname, binding->domainname); 00126 if (compare == 0) 00127 /* We found it! */ 00128 break; 00129 if (compare < 0) 00130 { 00131 /* It is not in the list. */ 00132 binding = NULL; 00133 break; 00134 } 00135 } 00136 00137 if (binding != NULL) 00138 { 00139 if (dirnamep) 00140 { 00141 const char *dirname = *dirnamep; 00142 00143 if (dirname == NULL) 00144 /* The current binding has be to returned. */ 00145 *dirnamep = binding->dirname; 00146 else 00147 { 00148 /* The domain is already bound. If the new value and the old 00149 one are equal we simply do nothing. Otherwise replace the 00150 old binding. */ 00151 char *result = binding->dirname; 00152 if (strcmp (dirname, result) != 0) 00153 { 00154 if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) 00155 result = (char *) INTUSE(_nl_default_dirname); 00156 else 00157 { 00158 #if defined _LIBC || defined HAVE_STRDUP 00159 result = strdup (dirname); 00160 #else 00161 size_t len = strlen (dirname) + 1; 00162 result = (char *) malloc (len); 00163 if (__builtin_expect (result != NULL, 1)) 00164 memcpy (result, dirname, len); 00165 #endif 00166 } 00167 00168 if (__builtin_expect (result != NULL, 1)) 00169 { 00170 if (binding->dirname != INTUSE(_nl_default_dirname)) 00171 free (binding->dirname); 00172 00173 binding->dirname = result; 00174 modified = 1; 00175 } 00176 } 00177 *dirnamep = result; 00178 } 00179 } 00180 00181 if (codesetp) 00182 { 00183 const char *codeset = *codesetp; 00184 00185 if (codeset == NULL) 00186 /* The current binding has be to returned. */ 00187 *codesetp = binding->codeset; 00188 else 00189 { 00190 /* The domain is already bound. If the new value and the old 00191 one are equal we simply do nothing. Otherwise replace the 00192 old binding. */ 00193 char *result = binding->codeset; 00194 if (result == NULL || strcmp (codeset, result) != 0) 00195 { 00196 #if defined _LIBC || defined HAVE_STRDUP 00197 result = strdup (codeset); 00198 #else 00199 size_t len = strlen (codeset) + 1; 00200 result = (char *) malloc (len); 00201 if (__builtin_expect (result != NULL, 1)) 00202 memcpy (result, codeset, len); 00203 #endif 00204 00205 if (__builtin_expect (result != NULL, 1)) 00206 { 00207 if (binding->codeset != NULL) 00208 free (binding->codeset); 00209 00210 binding->codeset = result; 00211 binding->codeset_cntr++; 00212 modified = 1; 00213 } 00214 } 00215 *codesetp = result; 00216 } 00217 } 00218 } 00219 else if ((dirnamep == NULL || *dirnamep == NULL) 00220 && (codesetp == NULL || *codesetp == NULL)) 00221 { 00222 /* Simply return the default values. */ 00223 if (dirnamep) 00224 *dirnamep = INTUSE(_nl_default_dirname); 00225 if (codesetp) 00226 *codesetp = NULL; 00227 } 00228 else 00229 { 00230 /* We have to create a new binding. */ 00231 size_t len = strlen (domainname) + 1; 00232 struct binding *new_binding = 00233 (struct binding *) malloc (offsetof (struct binding, domainname) + len); 00234 00235 if (__builtin_expect (new_binding == NULL, 0)) 00236 goto failed; 00237 00238 memcpy (new_binding->domainname, domainname, len); 00239 00240 if (dirnamep) 00241 { 00242 const char *dirname = *dirnamep; 00243 00244 if (dirname == NULL) 00245 /* The default value. */ 00246 dirname = INTUSE(_nl_default_dirname); 00247 else 00248 { 00249 if (strcmp (dirname, INTUSE(_nl_default_dirname)) == 0) 00250 dirname = INTUSE(_nl_default_dirname); 00251 else 00252 { 00253 char *result; 00254 #if defined _LIBC || defined HAVE_STRDUP 00255 result = strdup (dirname); 00256 if (__builtin_expect (result == NULL, 0)) 00257 goto failed_dirname; 00258 #else 00259 size_t len = strlen (dirname) + 1; 00260 result = (char *) malloc (len); 00261 if (__builtin_expect (result == NULL, 0)) 00262 goto failed_dirname; 00263 memcpy (result, dirname, len); 00264 #endif 00265 dirname = result; 00266 } 00267 } 00268 *dirnamep = dirname; 00269 new_binding->dirname = (char *) dirname; 00270 } 00271 else 00272 /* The default value. */ 00273 new_binding->dirname = (char *) INTUSE(_nl_default_dirname); 00274 00275 new_binding->codeset_cntr = 0; 00276 00277 if (codesetp) 00278 { 00279 const char *codeset = *codesetp; 00280 00281 if (codeset != NULL) 00282 { 00283 char *result; 00284 00285 #if defined _LIBC || defined HAVE_STRDUP 00286 result = strdup (codeset); 00287 if (__builtin_expect (result == NULL, 0)) 00288 goto failed_codeset; 00289 #else 00290 size_t len = strlen (codeset) + 1; 00291 result = (char *) malloc (len); 00292 if (__builtin_expect (result == NULL, 0)) 00293 goto failed_codeset; 00294 memcpy (result, codeset, len); 00295 #endif 00296 codeset = result; 00297 new_binding->codeset_cntr++; 00298 } 00299 *codesetp = codeset; 00300 new_binding->codeset = (char *) codeset; 00301 } 00302 else 00303 new_binding->codeset = NULL; 00304 00305 /* Now enqueue it. */ 00306 if (_nl_domain_bindings == NULL 00307 || strcmp (domainname, _nl_domain_bindings->domainname) < 0) 00308 { 00309 new_binding->next = _nl_domain_bindings; 00310 _nl_domain_bindings = new_binding; 00311 } 00312 else 00313 { 00314 binding = _nl_domain_bindings; 00315 while (binding->next != NULL 00316 && strcmp (domainname, binding->next->domainname) > 0) 00317 binding = binding->next; 00318 00319 new_binding->next = binding->next; 00320 binding->next = new_binding; 00321 } 00322 00323 modified = 1; 00324 00325 /* Here we deal with memory allocation failures. */ 00326 if (0) 00327 { 00328 failed_codeset: 00329 if (new_binding->dirname != INTUSE(_nl_default_dirname)) 00330 free (new_binding->dirname); 00331 failed_dirname: 00332 free (new_binding); 00333 failed: 00334 if (dirnamep) 00335 *dirnamep = NULL; 00336 if (codesetp) 00337 *codesetp = NULL; 00338 } 00339 } 00340 00341 /* If we modified any binding, we flush the caches. */ 00342 if (modified) 00343 ++_nl_msg_cat_cntr; 00344 00345 __libc_rwlock_unlock (_nl_state_lock); 00346 }
|
|
|
Definition at line 363 of file bindtextdom.c. Referenced by _nl_find_domain(), locale_charset(), and set_binding_values(). |
|
|
Definition at line 91 of file bindtextdom.c. |
|
|
Definition at line 353 of file bindtextdom.c. Referenced by set_binding_values(). |
|
|
Definition at line 91 of file bindtextdom.c. |
|
|
Definition at line 352 of file bindtextdom.c. |