From: Paul Eggert Date: Tue, 21 Sep 2004 22:05:27 +0000 (+0000) Subject: Reject unknown options. X-Git-Tag: v5.3.0~658 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c9dc0efd9f2e179625cf735de90cc1b8de26202;p=thirdparty%2Fcoreutils.git Reject unknown options. --- diff --git a/src/link.c b/src/link.c index 1e3754deec..cbe95867e6 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); }