diff options
author | Ruediger Meier | 2017-06-19 00:02:44 +0200 |
---|---|---|
committer | Ruediger Meier | 2017-06-26 14:38:24 +0200 |
commit | 6d7bee26bc4f5586b073f9b539453a7499403ea7 (patch) | |
tree | 1a620a48334963f9a25cc021b28d252cb10e71eb /misc-utils/getopt.c | |
parent | tools: add checkusage.sh (diff) | |
download | kernel-qcow2-util-linux-6d7bee26bc4f5586b073f9b539453a7499403ea7.tar.gz kernel-qcow2-util-linux-6d7bee26bc4f5586b073f9b539453a7499403ea7.tar.xz kernel-qcow2-util-linux-6d7bee26bc4f5586b073f9b539453a7499403ea7.zip |
flock, getopt: write --help to stdout and return 0
... and use errtryhelp() instead of usage().
Note in past "getopt --help" returned 2. But it is otherwise
documented and was just a mistake IMO. See the unreachable exit(0)
which was removed here: d1d03b54
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'misc-utils/getopt.c')
-rw-r--r-- | misc-utils/getopt.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index af4cf386a..87d088ed5 100644 --- a/misc-utils/getopt.c +++ b/misc-utils/getopt.c @@ -243,9 +243,7 @@ static void __attribute__ ((__noreturn__)) parse_error(const char *message) { if (message) warnx("%s", message); - fprintf(stderr, _("Try `%s --help' for more information.\n"), - program_invocation_short_name); - exit(PARAMETER_EXIT_CODE); + errtryhelp(PARAMETER_EXIT_CODE); } @@ -325,33 +323,33 @@ static shell_t shell_type(const char *new_shell) parse_error(_("unknown shell after -s or --shell argument")); } -static void __attribute__ ((__noreturn__)) print_help(void) +static void __attribute__((__noreturn__)) usage(void) { - fputs(USAGE_HEADER, stderr); - fprintf(stderr, _( + fputs(USAGE_HEADER, stdout); + printf(_( " %1$s <optstring> <parameters>\n" " %1$s [options] [--] <optstring> <parameters>\n" " %1$s [options] -o|--options <optstring> [options] [--] <parameters>\n"), program_invocation_short_name); - fputs(USAGE_SEPARATOR, stderr); - fputs(_("Parse command options.\n"), stderr); - - fputs(USAGE_OPTIONS, stderr); - fputs(_(" -a, --alternative allow long options starting with single -\n"), stderr); - fputs(_(" -l, --longoptions <longopts> the long options to be recognized\n"), stderr); - fputs(_(" -n, --name <progname> the name under which errors are reported\n"), stderr); - fputs(_(" -o, --options <optstring> the short options to be recognized\n"), stderr); - fputs(_(" -q, --quiet disable error reporting by getopt(3)\n"), stderr); - fputs(_(" -Q, --quiet-output no normal output\n"), stderr); - fputs(_(" -s, --shell <shell> set quoting conventions to those of <shell>\n"), stderr); - fputs(_(" -T, --test test for getopt(1) version\n"), stderr); - fputs(_(" -u, --unquoted do not quote the output\n"), stderr); - fputs(USAGE_SEPARATOR, stderr); - fputs(USAGE_HELP, stderr); - fputs(USAGE_VERSION, stderr); - fprintf(stderr, USAGE_MAN_TAIL("getopt(1)")); - exit(PARAMETER_EXIT_CODE); + fputs(USAGE_SEPARATOR, stdout); + fputs(_("Parse command options.\n"), stdout); + + fputs(USAGE_OPTIONS, stdout); + fputs(_(" -a, --alternative allow long options starting with single -\n"), stdout); + fputs(_(" -l, --longoptions <longopts> the long options to be recognized\n"), stdout); + fputs(_(" -n, --name <progname> the name under which errors are reported\n"), stdout); + fputs(_(" -o, --options <optstring> the short options to be recognized\n"), stdout); + fputs(_(" -q, --quiet disable error reporting by getopt(3)\n"), stdout); + fputs(_(" -Q, --quiet-output no normal output\n"), stdout); + fputs(_(" -s, --shell <shell> set quoting conventions to those of <shell>\n"), stdout); + fputs(_(" -T, --test test for getopt(1) version\n"), stdout); + fputs(_(" -u, --unquoted do not quote the output\n"), stdout); + fputs(USAGE_SEPARATOR, stdout); + fputs(USAGE_HELP, stdout); + fputs(USAGE_VERSION, stdout); + printf(USAGE_MAN_TAIL("getopt(1)")); + exit(EXIT_SUCCESS); } int main(int argc, char *argv[]) @@ -417,7 +415,7 @@ int main(int argc, char *argv[]) getopt_long_fp = getopt_long_only; break; case 'h': - print_help(); + usage(); case 'o': free(ctl.optstr); ctl.optstr = xstrdup(optarg); |