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.1to1.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 Free Software Foundation, Inc. 3 3 Written by Ulrich Drepper <[email protected]>, 1995. 4 4 … … 80 80 file and the name space must not be polluted. */ 81 81 # define strcasecmp __strcasecmp 82 83 84 85 86 87 88 89 82 90 #endif 83 91 … … 126 134 127 135 136 137 138 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 146 159 size_t added; 160 161 162 163 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 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 231 232 233 205 234 memcpy (full_fname, fname, fname_len); 206 235 memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); 236 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 char buf[BUFSIZ]; 254 char *alias; 255 char *value; 256 char *cp; 257 258 if (fgets (buf, , fp) == NULL) 229 259 /* EOF reached. */ 230 260 break; 261 262 263 264 265 266 267 268 269 270 271 272 273 231 274 232 275 cp = buf; … … 251 294 if (cp[0] != '\0') 252 295 { 253 char *tp;254 size_t len;296 ; 297 size_t 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 318 ) + 1; 319 320 if () 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 *) (new_size 371 )); 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 382 383 384 385 386 387 388 389 390 391 346 392 347 393 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
