summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Roskin2000-06-14 17:39:41 +0000
committerPavel Roskin2000-06-14 17:39:41 +0000
commite97da4007913bd29d8a18d038de29d9d4549163d (patch)
tree7a8cb9dac9f84df0c155b63308135d8b7b282d70
parent1af7ed5573de251690bae5ad70af1b3a6709457b (diff)
downloadbusybox-e97da4007913bd29d8a18d038de29d9d4549163d.zip
busybox-e97da4007913bd29d8a18d038de29d9d4549163d.tar.gz
Fixed "rm foo" that had been broken while implementing "rm -- foo"
-rw-r--r--Changelog2
-rw-r--r--coreutils/rm.c17
-rw-r--r--rm.c17
3 files changed, 23 insertions, 13 deletions
diff --git a/Changelog b/Changelog
index a55f7f3..bb3cc4a 100644
--- a/Changelog
+++ b/Changelog
@@ -61,7 +61,7 @@
* Fixed segfault caused by "rm -f"
* Fixed segfault caused by "ln -s -s" and similar abuses.
* Fixed segfault caused by "cp -a -a" and similar abuses.
- * Implemented "rm -- <foo>"
+ * Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
* "which" rewritten to use stat(). Fixes to improve its compatability
with traditional implementations -- Pavel Roskin.
* "mount" now reports errors from nfsmount() and assumes NFS mount
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 5901c5d..b1cda3a 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -68,14 +68,12 @@ extern int rm_main(int argc, char **argv)
int stopIt=FALSE;
struct stat statbuf;
- if (argc < 2) {
- usage(rm_usage);
- }
+ argc--;
argv++;
/* Parse any options */
- while (--argc >= 0 && *argv && **argv && stopIt==FALSE) {
- while (**argv == '-') {
+ while (argc > 0 && stopIt == FALSE) {
+ if (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'R':
@@ -91,8 +89,15 @@ extern int rm_main(int argc, char **argv)
default:
usage(rm_usage);
}
+ argc--;
+ argv++;
}
- argv++;
+ else
+ break;
+ }
+
+ if (argc < 1 && forceFlag == FALSE) {
+ usage(rm_usage);
}
while (argc-- > 0) {
diff --git a/rm.c b/rm.c
index 5901c5d..b1cda3a 100644
--- a/rm.c
+++ b/rm.c
@@ -68,14 +68,12 @@ extern int rm_main(int argc, char **argv)
int stopIt=FALSE;
struct stat statbuf;
- if (argc < 2) {
- usage(rm_usage);
- }
+ argc--;
argv++;
/* Parse any options */
- while (--argc >= 0 && *argv && **argv && stopIt==FALSE) {
- while (**argv == '-') {
+ while (argc > 0 && stopIt == FALSE) {
+ if (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'R':
@@ -91,8 +89,15 @@ extern int rm_main(int argc, char **argv)
default:
usage(rm_usage);
}
+ argc--;
+ argv++;
}
- argv++;
+ else
+ break;
+ }
+
+ if (argc < 1 && forceFlag == FALSE) {
+ usage(rm_usage);
}
while (argc-- > 0) {