From b301240424c7fed2ca8b836e2c9531d6ec59750d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 21 Oct 2019 17:20:34 -0500 Subject: Remove getdirname(), it's _not_ a drop-in replacement for dirname (it returns a malloc), and doesn't match the object lifetime of getbasename() (which always returns some or all of its argument string). The dirname() in libc modifies its argument string, but that's what posix says to do: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/dirname.html so I guess we can live with it. --- toys/posix/cp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'toys/posix/cp.c') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index bba54809..a843b90a 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -410,11 +410,10 @@ void cp_main(void) } if (destdir) { - char *s = FLAG(D) ? getdirname(src) : getbasename(src); + char *s = FLAG(D) ? dirname(src) : getbasename(src); TT.destname = xmprintf("%s/%s", destname, s); if (FLAG(D)) { - free(s); if (!(s = fileunderdir(TT.destname, destname))) { error_msg("%s not under %s", TT.destname, destname); continue; -- cgit v1.2.3