Changeset 609 for branches/GNU/src/binutils/intl/localealias.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/intl/localealias.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 /* Handle aliases for locale names 2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.1 /* Handle aliases for locale names. 2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. 3 3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. 4 4 … … 80 80 file and the name space must not be polluted. */ 81 81 # define strcasecmp __strcasecmp 82 83 # define mempcpy __mempcpy 84 # define HAVE_MEMPCPY 1 85 86 /* We need locking here since we can be called from different places. */ 87 # include <bits/libc-lock.h> 88 89 __libc_lock_define_initialized (static, lock); 82 90 #endif 83 91 … … 126 134 127 135 136 static char *string_space = NULL; 137 static size_t string_space_act = 0; 138 static size_t string_space_max = 0; 128 139 static struct alias_map *map; 129 140 static size_t nmap = 0; … … 132 143 133 144 /* Prototypes for local functions. */ 134 static size_t read_alias_file PARAMS ((const char *fname, int fname_len)); 145 static size_t read_alias_file PARAMS ((const char *fname, int fname_len)) 146 internal_function; 135 147 static void extend_alias_table PARAMS ((void)); 136 148 static int alias_compare PARAMS ((const struct alias_map *map1, … … 144 156 static const char *locale_alias_path = LOCALE_ALIAS_PATH; 145 157 struct alias_map *retval; 158 const char *result = NULL; 146 159 size_t added; 160 161 #ifdef _LIBC 162 __libc_lock_lock (lock); 163 #endif 147 164 148 165 do … … 163 180 /* We really found an alias. Return the value. */ 164 181 if (retval != NULL) 165 return retval->value; 182 { 183 result = retval->value; 184 break; 185 } 166 186 167 187 /* Perhaps we can find another alias file. */ … … 184 204 while (added != 0); 185 205 186 return NULL; 206 #ifdef _LIBC 207 __libc_lock_unlock (lock); 208 #endif 209 210 return result; 187 211 } 188 212 189 213 190 214 static size_t 215 internal_function 191 216 read_alias_file (fname, fname_len) 192 217 const char *fname; … … 203 228 full_fname = (char *) alloca (fname_len + sizeof aliasfile); 204 229 ADD_BLOCK (block_list, full_fname); 230 #ifdef HAVE_MEMPCPY 231 mempcpy (mempcpy (full_fname, fname, fname_len), 232 aliasfile, sizeof aliasfile); 233 #else 205 234 memcpy (full_fname, fname, fname_len); 206 235 memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); 236 #endif 207 237 208 238 fp = fopen (full_fname, "r"); … … 221 251 be that long 222 252 */ 223 char buf[BUFSIZ];224 char *alias;225 char *value;226 char *cp;227 228 if (fgets (buf, BUFSIZ, fp) == NULL)253 unsigned char buf[BUFSIZ]; 254 unsigned char *alias; 255 unsigned char *value; 256 unsigned char *cp; 257 258 if (fgets (buf, sizeof buf, fp) == NULL) 229 259 /* EOF reached. */ 230 260 break; 261 262 /* Possibly not the whole line fits into the buffer. Ignore 263 the rest of the line. */ 264 if (strchr (buf, '\n') == NULL) 265 { 266 char altbuf[BUFSIZ]; 267 do 268 if (fgets (altbuf, sizeof altbuf, fp) == NULL) 269 /* Make sure the inner loop will be left. The outer loop 270 will exit at the `feof' test. */ 271 break; 272 while (strchr (altbuf, '\n') == NULL); 273 } 231 274 232 275 cp = buf; … … 251 294 if (cp[0] != '\0') 252 295 { 253 char *tp;254 size_t len;296 size_t alias_len; 297 size_t value_len; 255 298 256 299 value = cp++; … … 272 315 extend_alias_table (); 273 316 274 /* We cannot depend on strdup available in the libc. Sigh! */275 len = strlen (alias) + 1;276 tp = (char *) malloc (len); 277 if ( tp == NULL)317 alias_len = strlen (alias) + 1; 318 value_len = strlen (value) + 1; 319 320 if (string_space_act + alias_len + value_len > string_space_max) 278 321 { 279 FREE_BLOCKS (block_list); 280 return added; 322 /* Increase size of memory pool. */ 323 size_t new_size = (string_space_max 324 + (alias_len + value_len > 1024 325 ? alias_len + value_len : 1024)); 326 char *new_pool = (char *) realloc (string_space, new_size); 327 if (new_pool == NULL) 328 { 329 FREE_BLOCKS (block_list); 330 return added; 331 } 332 string_space = new_pool; 333 string_space_max = new_size; 281 334 } 282 memcpy (tp, alias, len); 283 map[nmap].alias = tp; 284 285 len = strlen (value) + 1; 286 tp = (char *) malloc (len); 287 if (tp == NULL) 288 { 289 FREE_BLOCKS (block_list); 290 return added; 291 } 292 memcpy (tp, value, len); 293 map[nmap].value = tp; 335 336 map[nmap].alias = memcpy (&string_space[string_space_act], 337 alias, alias_len); 338 string_space_act += alias_len; 339 340 map[nmap].value = memcpy (&string_space[string_space_act], 341 value, value_len); 342 string_space_act += value_len; 294 343 295 344 ++nmap; … … 297 346 } 298 347 } 299 300 /* Possibly not the whole line fits into the buffer. Ignore301 the rest of the line. */302 while (strchr (cp, '\n') == NULL)303 {304 cp = buf;305 if (fgets (buf, BUFSIZ, fp) == NULL)306 /* Make sure the inner loop will be left. The outer loop307 will exit at the `feof' test. */308 *cp = '\n';309 }310 348 } 311 349 … … 330 368 331 369 new_size = maxmap == 0 ? 100 : 2 * maxmap; 332 new_map = (struct alias_map *) malloc(new_size333 * sizeof (struct alias_map));370 new_map = (struct alias_map *) realloc (map, (new_size 371 * sizeof (struct alias_map))); 334 372 if (new_map == NULL) 335 373 /* Simply don't extend: we don't have any more core. */ 336 374 return; 337 375 338 memcpy (new_map, map, nmap * sizeof (struct alias_map));339 340 if (maxmap != 0)341 free (map);342 343 376 map = new_map; 344 377 maxmap = new_size; 345 378 } 379 380 381 #ifdef _LIBC 382 static void __attribute__ ((unused)) 383 free_mem (void) 384 { 385 if (string_space != NULL) 386 free (string_space); 387 if (map != NULL) 388 free (map); 389 } 390 text_set_element (__libc_subfreeres, free_mem); 391 #endif 346 392 347 393 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.