Fixed "rm foo" that had been broken while implementing "rm -- foo"
authorPavel Roskin <proski@gnu.org>
Wed, 14 Jun 2000 17:39:41 +0000 (17:39 -0000)
committerPavel Roskin <proski@gnu.org>
Wed, 14 Jun 2000 17:39:41 +0000 (17:39 -0000)
Changelog
coreutils/rm.c
rm.c

index a55f7f3864050102ae8e00418d4b7846c8ef5dc8..bb3cc4aa312219d22ea96bfae5f3b7b1d6c577ae 100644 (file)
--- 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
index 5901c5da9b631ff37d25be79f87c6ce4ebaee825..b1cda3aed061c0fa8e3d9a3b67da0cb7f6a498b1 100644 (file)
@@ -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 5901c5da9b631ff37d25be79f87c6ce4ebaee825..b1cda3aed061c0fa8e3d9a3b67da0cb7f6a498b1 100644 (file)
--- 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) {