Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/intl/localealias.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.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.
    33   Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
    44
     
    8080   file and the name space must not be polluted.  */
    8181# 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);
    8290#endif
    8391
     
    126134
    127135
     136static char *string_space = NULL;
     137static size_t string_space_act = 0;
     138static size_t string_space_max = 0;
    128139static struct alias_map *map;
    129140static size_t nmap = 0;
     
    132143
    133144/* Prototypes for local functions.  */
    134 static size_t read_alias_file PARAMS ((const char *fname, int fname_len));
     145static size_t read_alias_file PARAMS ((const char *fname, int fname_len))
     146     internal_function;
    135147static void extend_alias_table PARAMS ((void));
    136148static int alias_compare PARAMS ((const struct alias_map *map1,
     
    144156  static const char *locale_alias_path = LOCALE_ALIAS_PATH;
    145157  struct alias_map *retval;
     158  const char *result = NULL;
    146159  size_t added;
     160
     161#ifdef _LIBC
     162  __libc_lock_lock (lock);
     163#endif
    147164
    148165  do
     
    163180      /* We really found an alias.  Return the value.  */
    164181      if (retval != NULL)
    165         return retval->value;
     182        {
     183          result = retval->value;
     184          break;
     185        }
    166186
    167187      /* Perhaps we can find another alias file.  */
     
    184204  while (added != 0);
    185205
    186   return NULL;
     206#ifdef _LIBC
     207  __libc_lock_unlock (lock);
     208#endif
     209
     210  return result;
    187211}
    188212
    189213
    190214static size_t
     215internal_function
    191216read_alias_file (fname, fname_len)
    192217     const char *fname;
     
    203228  full_fname = (char *) alloca (fname_len + sizeof aliasfile);
    204229  ADD_BLOCK (block_list, full_fname);
     230#ifdef HAVE_MEMPCPY
     231  mempcpy (mempcpy (full_fname, fname, fname_len),
     232           aliasfile, sizeof aliasfile);
     233#else
    205234  memcpy (full_fname, fname, fname_len);
    206235  memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile);
     236#endif
    207237
    208238  fp = fopen (full_fname, "r");
     
    221251            be that long
    222252       */
    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)
    229259        /* EOF reached.  */
    230260        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        }
    231274
    232275      cp = buf;
     
    251294          if (cp[0] != '\0')
    252295            {
    253               char *tp;
    254               size_t len;
     296              size_t alias_len;
     297              size_t value_len;
    255298
    256299              value = cp++;
     
    272315                extend_alias_table ();
    273316
    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)
    278321                {
    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;
    281334                }
    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;
    294343
    295344              ++nmap;
     
    297346            }
    298347        }
    299 
    300       /* Possibly not the whole line fits into the buffer.  Ignore
    301          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 loop
    307                will exit at the `feof' test.  */
    308             *cp = '\n';
    309         }
    310348    }
    311349
     
    330368
    331369  new_size = maxmap == 0 ? 100 : 2 * maxmap;
    332   new_map = (struct alias_map *) malloc (new_size
    333                                          * sizeof (struct alias_map));
     370  new_map = (struct alias_map *) realloc (map, (new_size
     371                                                * sizeof (struct alias_map)));
    334372  if (new_map == NULL)
    335373    /* Simply don't extend: we don't have any more core.  */
    336374    return;
    337375
    338   memcpy (new_map, map, nmap * sizeof (struct alias_map));
    339 
    340   if (maxmap != 0)
    341     free (map);
    342 
    343376  map = new_map;
    344377  maxmap = new_size;
    345378}
     379
     380
     381#ifdef _LIBC
     382static void __attribute__ ((unused))
     383free_mem (void)
     384{
     385  if (string_space != NULL)
     386    free (string_space);
     387  if (map != NULL)
     388    free (map);
     389}
     390text_set_element (__libc_subfreeres, free_mem);
     391#endif
    346392
    347393
Note: See TracChangeset for help on using the changeset viewer.