diff options
author | Rob Landley <rob@landley.net> | 2013-01-05 00:44:24 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-01-05 00:44:24 -0600 |
commit | 41ed9793498916c63d375326ea8c9b3fa1479dd6 (patch) | |
tree | 85cbe885f586ac1c0402b3bf3b3b3e7f7afa618b /toys | |
parent | 90e8605ea587c4ebd00de77e3c71551b6e26b7c0 (diff) | |
download | toybox-41ed9793498916c63d375326ea8c9b3fa1479dd6.tar.gz |
Use basename() where appropriate.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/other/rmmod.c | 4 | ||||
-rw-r--r-- | toys/posix/ln.c | 7 | ||||
-rw-r--r-- | toys/posix/rmdir.c | 13 |
3 files changed, 12 insertions, 12 deletions
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]); } } |