From 0f2658c806586190be3aca21826e77fff9e50f1b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 6 Oct 2020 15:50:15 -0500 Subject: The non-recursive dirtree_path wasn't stripping a trailing / from initial path. --- lib/dirtree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/dirtree.c b/lib/dirtree.c index 37581829..2bd7c404 100644 --- a/lib/dirtree.c +++ b/lib/dirtree.c @@ -85,15 +85,17 @@ char *dirtree_path(struct dirtree *node, int *plen) { struct dirtree *nn; char *path; - int ll, len; + int ii, ll, len; + if (!node->parent) return xstrdup(node->name); ll = len = plen ? *plen : 0; - for (nn = node; nn; nn = nn->parent) if (*nn->name) len += strlen(nn->name)+1; + for (nn = node; nn; nn = nn->parent) + if ((ii = strlen(nn->name))) len += ii+1-(nn->name[ii-1]=='/'); if (plen) *plen = len; - if (!len) return xstrdup(""); path = xmalloc(len)+len-ll; for (nn = node; nn; nn = nn->parent) if ((len = strlen(nn->name))) { *--path = '/'*(nn != node); + if (nn->name[len-1]=='/') len--; memcpy(path -= len, nn->name, len); } -- cgit v1.2.3