summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-09-21 22:01:28 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-09-21 22:01:28 +0000
commit0d219ee57d8cab4a78432c97754e22dd9248951e (patch)
tree3961a09c2d308664d061a1ff8a123b11e7e9dc02 /src
parentd243dee60af680588ef404cf1ac0353663710f69 (diff)
downloadcoreutils-0d219ee57d8cab4a78432c97754e22dd9248951e.tar.xz
Include <getopt.h>.
(main): Reject unknown options.
Diffstat (limited to 'src')
-rw-r--r--src/basename.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/basename.c b/src/basename.c
index 261200206..79fdd091e 100644
--- a/src/basename.c
+++ b/src/basename.c
@@ -26,6 +26,7 @@
=> functions.lis */
#include <config.h>
+#include <getopt.h>
#include <stdio.h>
#include <sys/types.h>
@@ -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);