From 725328c2098baac4d7c67f7308bf449c4d057e15 Mon Sep 17 00:00:00 2001 From: John Johansen Date: Fri, 12 Feb 2010 13:51:27 -0800 Subject: [PATCH] Allow for a location to alias to multiple locations. Ie. alias / -> /rofs, alias / -> /rwfs, --- parser/parser_alias.c | 14 ++++++++++---- parser/tst/simple_tests/rewrite/alias_dupe_1.sd | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/parser/parser_alias.c b/parser/parser_alias.c index 7c821f869..81c65fb21 100644 --- a/parser/parser_alias.c +++ b/parser/parser_alias.c @@ -39,19 +39,24 @@ static int compare_alias(const void *a, const void *b) { char *a_name = ((struct alias_rule *) a)->from; char *b_name = ((struct alias_rule *) b)->from; - return strcmp(a_name, b_name); + int res = strcmp(a_name, b_name); + if (res == 0) { + a_name = ((struct alias_rule *) a)->to; + b_name = ((struct alias_rule *) b)->to; + res = strcmp(a_name, b_name); + } + return res; } int new_alias(const char *from, const char *to) { struct alias_rule *alias, **result; - alias = malloc(sizeof(struct alias_rule)); + alias = calloc(1, sizeof(struct alias_rule)); if (!alias) { PERROR("Failed to allocate memory: %s\n", strerror(errno)); goto fail; } - memset(alias, 0, sizeof(*alias)); alias->from = strdup(from); if (!alias->from) { PERROR("Failed to allocate memory: %s\n", strerror(errno)); @@ -85,7 +90,8 @@ fail: free(alias->to); free(alias); } - return 0; + /* just drop duplicate aliases don't actually fail */ + return 1; } static char *do_alias(struct alias_rule *alias, const char *target) diff --git a/parser/tst/simple_tests/rewrite/alias_dupe_1.sd b/parser/tst/simple_tests/rewrite/alias_dupe_1.sd index 8de53845f..28fa7ea0d 100644 --- a/parser/tst/simple_tests/rewrite/alias_dupe_1.sd +++ b/parser/tst/simple_tests/rewrite/alias_dupe_1.sd @@ -1,5 +1,5 @@ #=DESCRIPTION Test of duplicate alias detection -#=EXRESULT FAIL +#=EXRESULT PASS @{MEEP} = meep moop alias /etc -> /Etcetera,