aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/lib.c15
-rw-r--r--lib/lib.h1
-rw-r--r--toys/posix/cp.c3
3 files changed, 1 insertions, 18 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 22b85b06..03c1db69 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1005,21 +1005,6 @@ void mode_to_string(mode_t mode, char *buf)
*buf = c;
}
-// dirname() can modify its argument or return a pointer to a constant string
-// This returns a malloc() copy of everyting before last (run of ) '/',
-// or "." if no path.
-char *getdirname(char *name)
-{
- char *s, *ss, *keep;
-
- for (s = name, ss = keep = 0; ; s++) {
- if (!s || !*s) return keep ? xstrndup(name, keep-name) : xstrdup(".");
- if (*s != '/') keep = ss;
- else if (s == name) keep = ss = s+1;
- else if (s[-1] != '/') ss = s;
- }
-}
-
// basename() can modify its argument or return a pointer to a constant string
// This just gives after the last '/' or the whole stirng if no /
char *getbasename(char *name)
diff --git a/lib/lib.h b/lib/lib.h
index 6d63bb09..b48d320e 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -400,7 +400,6 @@ void list_signals();
mode_t string_to_mode(char *mode_str, mode_t base);
void mode_to_string(mode_t mode, char *buf);
-char *getdirname(char *name);
char *getbasename(char *name);
char *fileunderdir(char *file, char *dir);
void names_to_pid(char **names, int (*callback)(pid_t pid, char *name),
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;