In commit d6de2f198 (env, printenv: add -0/--null option, 2009-10-27)
the short options from 'env' were copied into 'printenv'. This is
incorrect since 'printenv' does not support 'i' and 'u', which were
the only options 'env' supported at the time.

Despite some poor error messages mentioned in the commit message,
there was no functionality difference. Therefore, I didn't feel it
warranted a NEWS entry. I also did not add a test because it seems
rather pointless to only test -i and -u and not all the other
unsupported short options.

I was tempted to suggest writing a script to compare the long options
v.s. short options. I thought it would be quite trivial if we
standardize styles to something like this:

   static struct option const long_options[] =
   {
    { .... },
   }

   static char const short_options[] = "...";

But I realized that gets a bit tricky with source files like
lib/cksum.c, which are used for multiple programs.

I also remember Bruno wrote the 'options' Gnulib module to avoid
mistakes like this.

-- 8< --

This patch only improves some error messages. Here is the behavior
before the patch:

    $ printenv -i
    Try 'printenv --help' for more information.
    $ printenv -u
    printenv: option requires an argument -- 'u'
    Try 'printenv --help' for more information.
    $ printenv -u a
    Try 'printenv --help' for more information.

Here is the behavior after:

    $ ./src/printenv -i
    ./src/printenv: invalid option -- 'i'
    Try './src/printenv --help' for more information.
    $ ./src/printenv -u
    ./src/printenv: invalid option -- 'u'
    Try './src/printenv --help' for more information.
    $ ./src/printenv -u a
    ./src/printenv: invalid option -- 'u'
    Try './src/printenv --help' for more information.

* src/printenv.c (main): Remove 'i' and 'u' from the short options given
to getopt_long.
---
 src/printenv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/printenv.c b/src/printenv.c
index 1f68dd2cc..c2b1c69cd 100644
--- a/src/printenv.c
+++ b/src/printenv.c
@@ -93,7 +93,7 @@ main (int argc, char **argv)
   atexit (close_stdout);
 
   int optc;
-  while ((optc = getopt_long (argc, argv, "+iu:0", longopts, NULL)) != -1)
+  while ((optc = getopt_long (argc, argv, "+0", longopts, NULL)) != -1)
     {
       switch (optc)
         {
-- 
2.54.0


Reply via email to