From 0d219ee57d8cab4a78432c97754e22dd9248951e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 21 Sep 2004 22:01:28 +0000 Subject: [PATCH] Include . (main): Reject unknown options. --- src/basename.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/basename.c b/src/basename.c index 2612002..79fdd09 100644 --- a/src/basename.c +++ b/src/basename.c @@ -26,6 +26,7 @@ => functions.lis */ #include +#include #include #include @@ -102,31 +103,26 @@ main (int argc, char **argv) parse_long_options (argc, argv, PROGRAM_NAME, GNU_PACKAGE, VERSION, usage, AUTHORS, (char const *) NULL); - /* The above handles --help and --version. - Since there is no other invocation of getopt, handle `--' here. */ - if (argc > 1 && STREQ (argv[1], "--")) - { - --argc; - ++argv; - } + if (getopt (argc, argv, "+") != -1) + usage (EXIT_FAILURE); - if (argc < 2) + if (argc < optind + 1) { error (0, 0, _("missing operand")); 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); } - name = base_name (argv[1]); + name = base_name (argv[optind]); name[base_len (name)] = '\0'; - if (argc == 3) - remove_suffix (name, argv[2]); + if (argc == optind + 2) + remove_suffix (name, argv[optind + 1]); puts (name); -- 2.7.4