diff options
Diffstat (limited to 'intl/localealias.c')
-rw-r--r-- | intl/localealias.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/intl/localealias.c b/intl/localealias.c index 17b912afb3..57c4a01588 100644 --- a/intl/localealias.c +++ b/intl/localealias.c @@ -77,6 +77,41 @@ void free (); # define strcasecmp __strcasecmp #endif + +/* For those loosing systems which don't have `alloca' we have to add + some additional code emulating it. */ +#ifdef HAVE_ALLOCA +/* Nothing has to be done. */ +# define ADD_BLOCK(list, address) /* nothing */ +# define FREE_BLOCKS(list) /* nothing */ +#else +struct block_list +{ + void *address; + struct block_list *next; +}; +# define ADD_BLOCK(list, addr) \ + do { \ + struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \ + /* If we cannot get a free block we cannot add the new element to \ + the list. */ \ + if (newp != NULL) { \ + newp->address = (addr); \ + newp->next = (list); \ + (list) = newp; \ + } \ + } while (0) +# define FREE_BLOCKS(list) \ + do { \ + while (list != NULL) { \ + struct block_list *old = list; \ + list = list->next; \ + free (old); \ + } \ + } while (0) +#endif /* have alloca */ + + struct alias_map { const char *alias; @@ -151,18 +186,25 @@ read_alias_file (fname, fname_len) const char *fname; int fname_len; { +#ifndef HAVE_ALLOCA + struct block_list *alloca_list = NULL; +#endif FILE *fp; char *full_fname; size_t added; static const char aliasfile[] = "/locale.alias"; full_fname = (char *) alloca (fname_len + sizeof aliasfile); + ADD_BLOCK (block_list, full_fname); memcpy (full_fname, fname, fname_len); memcpy (&full_fname[fname_len], aliasfile, sizeof aliasfile); fp = fopen (full_fname, "r"); if (fp == NULL) - return 0; + { + FREE_BLOCKS (block_list); + return 0; + } added = 0; while (!feof (fp)) @@ -227,14 +269,20 @@ read_alias_file (fname, fname_len) len = strlen (alias) + 1; tp = (char *) malloc (len); if (tp == NULL) - return added; + { + FREE_BLOCKS (block_list); + return added; + } memcpy (tp, alias, len); map[nmap].alias = tp; len = strlen (value) + 1; tp = (char *) malloc (len); if (tp == NULL) - return added; + { + FREE_BLOCKS (block_list); + return added; + } memcpy (tp, value, len); map[nmap].value = tp; @@ -263,6 +311,7 @@ read_alias_file (fname, fname_len) qsort (map, nmap, sizeof (struct alias_map), (int (*) PARAMS ((const void *, const void *))) alias_compare); + FREE_BLOCKS (block_list); return added; } |