From 5782a362e17c9c97256b0456f36eb08f767a04e6 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Tue, 28 Nov 2017 17:32:29 +0100 Subject: all: use consistent diagnostics for unknown long options Previously, e.g. cksum failed to output the offending unknown long option: $ cksum --unknown-opt cksum: invalid option -- '-' Try 'cksum --help' for more information. i.e., it tried to diagnose '-' as short option. Instead, it should diagnose the unknown long option: $ cksum --unknown-opt cksum: unrecognized option '--unknown-opt' Try 'cksum --help' for more information. * src/cksum.c (long_options): Add struct with null entry only. (main): Use it in the getopt_long call. * src/dd.c: Likewise. * src/hostid.c: Likewise. * src/hostname.c: Likewise. * src/link.c: Likewise. * src/logname.c: Likewise. * src/nohup.c: Likewise. * src/sleep.c: Likewise. * src/tsort.c: Likewise. * src/unlink.c: Likewise. * src/uptime.c: Likewise. * src/users.c: Likewise. * src/whoami.c: Likewise. * src/yes.c: Likewise. * NEWS (Improvements): Mention the fix. --- src/hostname.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/hostname.c') diff --git a/src/hostname.c b/src/hostname.c index 0a57cb409..560eb7f43 100644 --- a/src/hostname.c +++ b/src/hostname.c @@ -33,6 +33,11 @@ #define AUTHORS proper_name ("Jim Meyering") +static struct option const long_options[] = +{ + {NULL, 0, NULL, 0} +}; + #if !defined HAVE_SETHOSTNAME && defined HAVE_SYSINFO && \ defined HAVE_SYS_SYSTEMINFO_H # include @@ -83,7 +88,7 @@ main (int argc, char **argv) parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); - if (getopt_long (argc, argv, "", NULL, NULL) != -1) + if (getopt_long (argc, argv, "", long_options, NULL) != -1) usage (EXIT_FAILURE); if (argc == optind + 1) -- cgit v1.2.1