diff options
Diffstat (limited to 'src/dirname.c')
-rw-r--r-- | src/dirname.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/dirname.c b/src/dirname.c index 552b6da0d..40a9b29ce 100644 --- a/src/dirname.c +++ b/src/dirname.c @@ -18,6 +18,7 @@ /* Written by David MacKenzie and Jim Meyering. */ #include <config.h> +#include <getopt.h> #include <stdio.h> #include <sys/types.h> @@ -77,27 +78,22 @@ 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 (2 < argc) + if (optind + 1 < argc) { - error (0, 0, _("extra operand %s"), quote (argv[2])); + error (0, 0, _("extra operand %s"), quote (argv[optind + 1])); usage (EXIT_FAILURE); } - result = argv[1]; + result = argv[optind]; len = dir_len (result); if (! len) |