summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-04-23 05:39:55 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-04-23 05:39:55 +0000
commitd3eadc9cbfc4387f9def0879551e86b5a21feb27 (patch)
tree5353ed7d21e8784faad93efba8c6469e812c7bab /src
parentdb3f41ec7755299742085475d18c609aa3c2e0cc (diff)
downloadcoreutils-d3eadc9cbfc4387f9def0879551e86b5a21feb27.tar.xz
(main): Report proper program name when getopt finds trouble.
Diffstat (limited to 'src')
-rw-r--r--src/nice.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/nice.c b/src/nice.c
index 689fa49dd..520821464 100644
--- a/src/nice.c
+++ b/src/nice.c
@@ -116,7 +116,7 @@ main (int argc, char **argv)
for (i = 1; i < argc; /* empty */)
{
- char *s = argv[i];
+ char const *s = argv[i];
if (s[0] == '-' && ISDIGIT (s[1 + (s[1] == '-' || s[1] == '+')])
&& posix2_version () < 200112)
@@ -127,28 +127,23 @@ main (int argc, char **argv)
else
{
int optc;
- char **fake_argv = argv + i - 1;
+ int fake_argc = argc - (i - 1);
+ char **fake_argv = argv + (i - 1);
+
+ /* Ensure that any getopt diagnostics use the right name. */
+ fake_argv[0] = program_name;
/* Initialize getopt_long's internal state. */
optind = 0;
- if ((optc = getopt_long (argc - (i - 1), fake_argv, "+n:",
- longopts, NULL)) != -1)
- {
- switch (optc)
- {
- case '?':
- usage (EXIT_FAIL);
-
- case 'n':
- adjustment_given = optarg;
- break;
- }
- }
-
+ optc = getopt_long (fake_argc, fake_argv, "+n:", longopts, NULL);
i += optind - 1;
- if (optc == EOF)
+ if (optc == '?')
+ usage (EXIT_FAIL);
+ else if (optc == 'n')
+ adjustment_given = optarg;
+ else /* optc == -1 */
break;
}
}