diff options
author | trasz <trasz@FreeBSD.org> | 2015-05-21 13:18:02 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2015-05-21 13:18:02 +0000 |
commit | eca8c46c2bbe0edd2bbe51ca88762dd06858464f (patch) | |
tree | 3f610a9f32117037279bfae1c4d53ce5b562f725 | |
parent | a151e5d0a47fd99bad0a0e2ce4711b08d0192e14 (diff) | |
download | FreeBSD-src-eca8c46c2bbe0edd2bbe51ca88762dd06858464f.zip FreeBSD-src-eca8c46c2bbe0edd2bbe51ca88762dd06858464f.tar.gz |
MFC r279806:
Minor optimization/cleanup in node_path(); no functional changes.
-rw-r--r-- | usr.sbin/autofs/common.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c index 8ace69d..8c455c4 100644 --- a/usr.sbin/autofs/common.c +++ b/usr.sbin/autofs/common.c @@ -561,7 +561,6 @@ static char * node_path_x(const struct node *n, char *x) { char *path; - size_t len; if (n->n_parent == NULL) return (x); @@ -580,14 +579,6 @@ node_path_x(const struct node *n, char *x) path = separated_concat(n->n_key, x, '/'); free(x); - /* - * Strip trailing slash. - */ - len = strlen(path); - assert(len > 0); - if (path[len - 1] == '/') - path[len - 1] = '\0'; - return (node_path_x(n->n_parent, path)); } @@ -598,8 +589,19 @@ node_path_x(const struct node *n, char *x) char * node_path(const struct node *n) { + char *path; + size_t len; + + path = node_path_x(n, checked_strdup("")); + + /* + * Strip trailing slash, unless the whole path is "/". + */ + len = strlen(path); + if (len > 1 && path[len - 1] == '/') + path[len - 1] = '\0'; - return (node_path_x(n, checked_strdup(""))); + return (path); } static char * |