/* The actual code to add aliases. */ static void add_alias2 (const char *from, const char *to, const char *wp, void *modules) { /* Test whether this alias conflicts with any available module. */ if (detect_conflict (from)) /* It does conflict, don't add the alias. */ return; struct gconv_alias *new_alias = (struct gconv_alias *) malloc (sizeof (struct gconv_alias) + (wp - from)); if (new_alias != NULL) { void **inserted; new_alias->fromname = memcpy ((char *) new_alias + sizeof (struct gconv_alias), from, wp - from); new_alias->toname = new_alias->fromname + (to - from); inserted = (void **) __tsearch (new_alias, &__gconv_alias_db, __gconv_alias_compare); if (inserted == NULL || *inserted != new_alias) /* Something went wrong, free this entry. */ free (new_alias); } }
/* Add new alias. */ static inline void add_alias (char *rp, void *modules) { /* We now expect two more string. The strings are normalized (converted to UPPER case) and strored in the alias database. */ struct gconv_alias *new_alias; char *from, *to, *wp; while (__isspace_l (*rp, &_nl_C_locobj)) ++rp; from = wp = rp; while (*rp != '\0' && !__isspace_l (*rp, &_nl_C_locobj)) *wp++ = __toupper_l (*rp++, &_nl_C_locobj); if (*rp == '\0') /* There is no `to' string on the line. Ignore it. */ return; *wp++ = '\0'; to = ++rp; while (__isspace_l (*rp, &_nl_C_locobj)) ++rp; while (*rp != '\0' && !__isspace_l (*rp, &_nl_C_locobj)) *wp++ = __toupper_l (*rp++, &_nl_C_locobj); if (to == wp) /* No `to' string, ignore the line. */ return; *wp++ = '\0'; /* Test whether this alias conflicts with any available module. */ if (detect_conflict (from)) /* It does conflict, don't add the alias. */ return; new_alias = (struct gconv_alias *) malloc (sizeof (struct gconv_alias) + (wp - from)); if (new_alias != NULL) { void **inserted; new_alias->fromname = memcpy ((char *) new_alias + sizeof (struct gconv_alias), from, wp - from); new_alias->toname = new_alias->fromname + (to - from); inserted = (void **) __tsearch (new_alias, &__gconv_alias_db, __gconv_alias_compare); if (inserted == NULL || *inserted != new_alias) /* Something went wrong, free this entry. */ free (new_alias); } }