ln: fixed command line parser. Added support for "--"
authorPavel Roskin <proski@gnu.org>
Thu, 15 Jun 2000 18:04:40 +0000 (18:04 -0000)
committerPavel Roskin <proski@gnu.org>
Thu, 15 Jun 2000 18:04:40 +0000 (18:04 -0000)
Changelog
coreutils/ln.c
ln.c

index d5c72684e49d95ff8252bef34bea98f2edd62c59..e3548257ae59205bc4400462f3ecde4fa26bf126 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -61,7 +61,8 @@
        * Simplified freeramdisk and added argument checking -- Pavel Roskin. 
        * Fixed segfault caused by "touch -c"
        * Fixed segfault caused by "rm -f"
-       * Fixed segfault caused by "ln -s -s" and similar abuses.
+       * Fixed segfault caused by "ln -s -s" and similar abuses. Further fixes
+           and "--" support from Pavel Roskin.
        * Fixed segfault caused by "cp -a -a" and similar abuses.
        * Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
        * "which" rewritten to use stat(). Fixes to improve its compatability
index d4fa47306b585164571b731091903b73b29301f0..634c9905dc8c2c0b161b493455919c5259936939 100644 (file)
@@ -51,16 +51,14 @@ extern int ln_main(int argc, char **argv)
 {
        char *linkName;
        int linkIntoDirFlag;
+       int stopIt = FALSE;
 
-       if (argc < 3) {
-               usage(ln_usage);
-       }
        argc--;
        argv++;
 
        /* Parse any options */
-       while (--argc >= 0 && *argv && **argv) {
-               while (**argv == '-') {
+       while (argc > 0 && stopIt == FALSE) {
+               if (**argv == '-') {
                        while (*++(*argv))
                                switch (**argv) {
                                        case 's':
@@ -72,15 +70,21 @@ extern int ln_main(int argc, char **argv)
                                        case 'n':
                                                followLinks = FALSE;
                                                break;
+                                       case '-':
+                                               stopIt = TRUE;
+                                               break;
                                        default:
                                                usage(ln_usage);
                                }
+                       argc--;
+                       argv++;
                }
-               argv++;
+               else
+                       break;
        }
 
-       if (argc < 1) {
-               fatalError("ln: missing file argument\n");
+       if (argc < 2) {
+               usage(ln_usage);
        }
 
        linkName = argv[argc - 1];
diff --git a/ln.c b/ln.c
index d4fa47306b585164571b731091903b73b29301f0..634c9905dc8c2c0b161b493455919c5259936939 100644 (file)
--- a/ln.c
+++ b/ln.c
@@ -51,16 +51,14 @@ extern int ln_main(int argc, char **argv)
 {
        char *linkName;
        int linkIntoDirFlag;
+       int stopIt = FALSE;
 
-       if (argc < 3) {
-               usage(ln_usage);
-       }
        argc--;
        argv++;
 
        /* Parse any options */
-       while (--argc >= 0 && *argv && **argv) {
-               while (**argv == '-') {
+       while (argc > 0 && stopIt == FALSE) {
+               if (**argv == '-') {
                        while (*++(*argv))
                                switch (**argv) {
                                        case 's':
@@ -72,15 +70,21 @@ extern int ln_main(int argc, char **argv)
                                        case 'n':
                                                followLinks = FALSE;
                                                break;
+                                       case '-':
+                                               stopIt = TRUE;
+                                               break;
                                        default:
                                                usage(ln_usage);
                                }
+                       argc--;
+                       argv++;
                }
-               argv++;
+               else
+                       break;
        }
 
-       if (argc < 1) {
-               fatalError("ln: missing file argument\n");
+       if (argc < 2) {
+               usage(ln_usage);
        }
 
        linkName = argv[argc - 1];