summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1998-07-02 15:58:53 +0000
committerConstantine Sapuntzakis <csapuntz@cvs.openbsd.org>1998-07-02 15:58:53 +0000
commit319c6854b2fd5485e5be744f9221bf9888e8fda3 (patch)
treedb19e2e810dc7ef1cf635ce44921be8d4f878f24 /bin
parent9d59fdf77480f56db168824cdad47161e940cb90 (diff)
Fix mv b/ a where a is a directory.
Diffstat (limited to 'bin')
-rw-r--r--bin/mv/mv.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 970fae2f4c3..fcbc3e44fe4 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mv.c,v 1.10 1998/05/18 19:11:45 deraadt Exp $ */
+/* $OpenBSD: mv.c,v 1.11 1998/07/02 15:58:52 csapuntz Exp $ */
/* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */
/*
@@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$OpenBSD: mv.c,v 1.10 1998/05/18 19:11:45 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: mv.c,v 1.11 1998/07/02 15:58:52 csapuntz Exp $";
#endif
#endif /* not lint */
@@ -130,16 +130,35 @@ main(argc, argv)
++baselen;
}
for (rval = 0; --argc; ++argv) {
- if ((p = strrchr(*argv, '/')) == NULL)
- p = *argv;
- else
- ++p;
+ char *current_arg = *argv;
+
+ /* Get the name of the file to create from
+ the argument. This is a bit tricky because
+ in the case of b/ we actually want b and empty
+ string */
+ if ((p = strrchr(current_arg, '/')) == NULL)
+ p = current_arg;
+ else {
+ /* Special case foo/ */
+ if (!*(p+1)) {
+ while ((p >= current_arg) &&
+ *p == '/')
+ p--;
+
+ while ((p >= current_arg) &&
+ *p != '/')
+ p--;
+ }
+
+ p++;
+ }
+
if ((baselen + (len = strlen(p))) >= MAXPATHLEN) {
warnx("%s: destination pathname too long", *argv);
rval = 1;
} else {
memmove(endp, p, len + 1);
- if (do_move(*argv, path))
+ if (do_move(current_arg, path))
rval = 1;
}
}