diff options
author | Pavel Roskin <proski@gnu.org> | 2000-06-15 22:04:40 +0400 |
---|---|---|
committer | Pavel Roskin <proski@gnu.org> | 2000-06-15 22:04:40 +0400 |
commit | 2e965239ee4f19f86e377ade94574c3c73a32425 (patch) | |
tree | d77dd91a7e2d4f2c8edab88b75daace67d828307 | |
parent | 3f75503fa0b747b6d505ffe8ec047f6894f81050 (diff) |
ln: fixed command line parser. Added support for "--"
-rw-r--r-- | Changelog | 3 | ||||
-rw-r--r-- | coreutils/ln.c | 20 | ||||
-rw-r--r-- | ln.c | 20 |
3 files changed, 26 insertions, 17 deletions
@@ -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 diff --git a/coreutils/ln.c b/coreutils/ln.c index d4fa47306..634c9905d 100644 --- a/coreutils/ln.c +++ b/coreutils/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]; @@ -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]; |