diff options
author | Bernhard Voelker <mail@bernhard-voelker.de> | 2017-11-28 17:32:29 +0100 |
---|---|---|
committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2017-11-29 13:27:02 +0100 |
commit | 5782a362e17c9c97256b0456f36eb08f767a04e6 (patch) | |
tree | 4854035457f7d9b705aaa49f90873c22e136a154 /src/hostname.c | |
parent | b505dc5734b551b34c9e95c8daa8d574d6d8636e (diff) | |
download | coreutils-5782a362e17c9c97256b0456f36eb08f767a04e6.tar.gz |
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.
Diffstat (limited to 'src/hostname.c')
-rw-r--r-- | src/hostname.c | 7 |
1 files changed, 6 insertions, 1 deletions
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 <sys/systeminfo.h> @@ -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) |