diff options
author | Rob Landley <rob@landley.net> | 2020-10-06 15:50:15 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-10-06 15:50:15 -0500 |
commit | 0f2658c806586190be3aca21826e77fff9e50f1b (patch) | |
tree | 0c24bb07fb084b2284b24c40e92429c9f458e862 /lib | |
parent | 841a7966d8a34906e1871572709270fe23b2ff9c (diff) | |
download | toybox-0f2658c806586190be3aca21826e77fff9e50f1b.tar.gz |
The non-recursive dirtree_path wasn't stripping a trailing / from initial path.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dirtree.c | 8 |
1 files changed, 5 insertions, 3 deletions
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); } |