This patch relates pull request created by E5ten https://github.com/landley/toybox/pull/145
I would write getdirname() following way so it should output similar output as libc dirname but return always pointer that can be freed. You might have more elegant solution but here is my take. return similar dirnames as libc dirname path getdirname /usr/lib/ /usr /usr/lib /usr /usr/ / usr . / / . . .. . --- lib/lib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
From 2197840947813992d3b7ef5e8230150fbb2872e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarno=20M=C3=A4kip=C3=A4=C3=A4?= <[email protected]> Date: Mon, 14 Oct 2019 17:50:07 +0300 Subject: [PATCH] lib getdirname() return similar dirnames as libc dirname path getdirname /usr/lib/ /usr /usr/lib /usr /usr/ / usr . / / . . .. . --- lib/lib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/lib.c b/lib/lib.c index fe402af8..25bd3b65 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1010,7 +1010,13 @@ char *getdirname(char *name) { char *s = xstrdup(name), *ss = strrchr(s, '/'); - while (ss && *ss && *ss == '/' && s != ss) *ss-- = 0; + if (!ss) free(s), xstrdup("."); + else { + ss = s+strlen(s)-1; + if (ss != s) do { + *ss-- = 0; + } while(*ss != '/'); + } return s; } -- 2.19.1
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
