From 41ed9793498916c63d375326ea8c9b3fa1479dd6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 5 Jan 2013 00:44:24 -0600 Subject: Use basename() where appropriate. --- toys/posix/rmdir.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'toys/posix/rmdir.c') 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]); } } -- cgit v1.2.3