aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c12
-rwxr-xr-xscripts/test/chgrp.test2
-rwxr-xr-xscripts/test/rmdir.test4
-rw-r--r--scripts/test/testing.sh2
-rw-r--r--toys/other/rmmod.c4
-rw-r--r--toys/posix/ln.c7
-rw-r--r--toys/posix/rmdir.c13
7 files changed, 19 insertions, 25 deletions
diff --git a/main.c b/main.c
index bf89ef21..9370efd3 100644
--- a/main.c
+++ b/main.c
@@ -146,16 +146,8 @@ int main(int argc, char *argv[])
{
if (CFG_TOYBOX_I18N) setlocale(LC_ALL, "");
- // Artificial scope to eat less stack for things we call
- {
- char *name;
-
- // Trim path off of command name
- name = strrchr(argv[0], '/');
- if (!name) name=argv[0];
- else name++;
- argv[0] = name;
- }
+ // Trim path off of command name
+ *argv = basename(*argv);
// Call the multiplexer, adjusting this argv[] to be its' argv[1].
// (It will adjust it back before calling toy_exec().)
diff --git a/scripts/test/chgrp.test b/scripts/test/chgrp.test
index 9c7142a4..2af93857 100755
--- a/scripts/test/chgrp.test
+++ b/scripts/test/chgrp.test
@@ -2,8 +2,6 @@
[ -f testing.sh ] && . testing.sh
-VERBOSE=1
-
if [ "$(id -u)" -ne 0 ]
then
echo "SKIPPED: chgrp (not root)"
diff --git a/scripts/test/rmdir.test b/scripts/test/rmdir.test
index bea75881..a7b027e0 100755
--- a/scripts/test/rmdir.test
+++ b/scripts/test/rmdir.test
@@ -45,6 +45,10 @@ mkdir -p one/two/three
testing "rmdir -p one/two/three" \
"rmdir -p one/two/three && [ ! -e one ] && echo yes" "yes\n" "" ""
+mkdir -p one/two/three
+testing "rmdir -p one/two/three/" \
+ "rmdir -p one/two/three/ && [ ! -e one ] && echo yes" "yes\n" "" ""
+
#mkdir -p one/two/three
#chmod 000 one/two/three one/two one
#testing "rmdir -p one/two/three" \
diff --git a/scripts/test/testing.sh b/scripts/test/testing.sh
index 0f72bce4..b7eacc68 100644
--- a/scripts/test/testing.sh
+++ b/scripts/test/testing.sh
@@ -74,7 +74,7 @@ testing ()
echo -ne "$5" | eval "$2" > actual
RETVAL=$?
- cmp expected actual > /dev/null
+ cmp expected actual > /dev/null 2>&1
if [ $? -ne 0 ]
then
FAILCOUNT=$[$FAILCOUNT+1]
diff --git a/toys/other/rmmod.c b/toys/other/rmmod.c
index 093eb8a1..b789acc6 100644
--- a/toys/other/rmmod.c
+++ b/toys/other/rmmod.c
@@ -29,9 +29,7 @@ void rmmod_main(void)
int len;
// Basename
- mod_name = strrchr(toys.optargs[0],'/');
- if (mod_name) mod_name++;
- else mod_name = toys.optargs[0];
+ mod_name = basename(*toys.optargs);
// Remove .ko if present
len = strlen(mod_name);
diff --git a/toys/posix/ln.c b/toys/posix/ln.c
index fea6fff2..d69aabf4 100644
--- a/toys/posix/ln.c
+++ b/toys/posix/ln.c
@@ -47,11 +47,8 @@ void ln_main(void)
int rc;
char *try = toys.optargs[i];
- if (S_ISDIR(buf.st_mode)) {
- new = strrchr(try, '/');
- if (!new) new = try;
- new = xmsprintf("%s/%s", dest, new);
- } else new = dest;
+ if (S_ISDIR(buf.st_mode)) new = xmsprintf("%s/%s", dest, basename(try));
+ else new = dest;
/* Silently unlink the existing target. If it doesn't exist,
* then we just move on */
if (toys.optflags & FLAG_f) unlink(new);
diff --git a/toys/posix/rmdir.c b/toys/posix/rmdir.c
index 289b0156..fec3ce98 100644
--- a/toys/posix/rmdir.c
+++ b/toys/posix/rmdir.c
@@ -20,16 +20,21 @@ config RMDIR
static void do_rmdir(char *name)
{
- for (;;) {
- char *temp;
+ char *temp;
+ for (;;) {
if (rmdir(name)) {
perror_msg("%s",name);
return;
}
+
+ // Each -p cycle back up one slash, ignoring trailing and repeated /.
+
if (!toys.optflags) return;
- if (!(temp=strrchr(name,'/'))) return;
- *temp=0;
+ do {
+ if (!(temp = strrchr(name, '/'))) return;
+ *temp = 0;
+ } while (!temp[1]);
}
}