diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-09-21 22:05:27 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-09-21 22:05:27 +0000 |
commit | 6c9dc0efd9f2e179625cf735de90cc1b8de26202 (patch) | |
tree | b47f78c2708f1118d1bbd5ac70835beaa125d504 | |
parent | b78d6f6d9224713f2003f39aaf640743408bcaae (diff) | |
download | coreutils-6c9dc0efd9f2e179625cf735de90cc1b8de26202.tar.xz |
Reject unknown options.
-rw-r--r-- | src/link.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/link.c b/src/link.c index 1e3754dee..cbe95867e 100644 --- a/src/link.c +++ b/src/link.c @@ -74,33 +74,27 @@ main (int argc, char **argv) parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION, usage, AUTHORS, (char const *) NULL); + if (getopt (argc, argv, "") != -1) + usage (EXIT_FAILURE); - /* The above handles --help and --version. - Since there is no other invocation of getopt, handle `--' here. */ - if (1 < argc && STREQ (argv[1], "--")) + if (argc < optind + 2) { - --argc; - ++argv; - } - - if (argc < 3) - { - if (argc < 2) + if (argc < optind + 1) error (0, 0, _("missing operand")); else - error (0, 0, _("missing operand after %s"), quote (argv[argc - 1])); + error (0, 0, _("missing operand after %s"), quote (argv[optind])); usage (EXIT_FAILURE); } - if (3 < argc) + if (optind + 2 < argc) { - error (0, 0, _("extra operand %s"), quote (argv[3])); + error (0, 0, _("extra operand %s"), quote (argv[optind + 2])); usage (EXIT_FAILURE); } - if (link (argv[1], argv[2]) != 0) + if (link (argv[optind], argv[optind + 1]) != 0) error (EXIT_FAILURE, errno, _("cannot create link %s to %s"), - quote_n (0, argv[2]), quote_n (1, argv[1])); + quote_n (0, argv[optind + 1]), quote_n (1, argv[optind])); exit (EXIT_SUCCESS); } |