]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix -W with optional parameters in getopt.
authorEric Blake <ebb9@byu.net>
Thu, 8 Apr 2010 00:16:27 +0000 (17:16 -0700)
committerPetr Baudis <pasky@ucw.cz>
Wed, 12 May 2010 01:21:14 +0000 (03:21 +0200)
According to the getopt documentation, if "W;" is part of optstring, then '-W
foo' should behave like '--foo'.  But if "foo" uses an optional_argument, this
is not the case, since optarg is not NULL when using -W.

(cherry picked from commit aa7f642769abcfbce658aeaaffdc9fb4790cd905)

ChangeLog
posix/getopt.c

index 6df5c047f76ce1c4c7f0b1b055e10332601fc1f1..9e247e87df059de1f1e2c645f9d094a24cc1b2da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-02  Eric Blake <ebb9@byu.net>
+
+       [BZ #11041]
+       * posix/getopt.c (_getopt_internal_r): Handle '-Wfoo' identically
+       to '--foo', with optional argument or non-ambiguous prefix.
+
 2010-04-05  Ulrich Drepper  <drepper@redhat.com>
 
        [BZ #11010]
index 88acff0e2f6f00e1508f151fab74717f95674bb8..01c1071ecb47d196c4035e47b3afa91e47c6ebf3 100644 (file)
@@ -911,7 +911,10 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
                  pfound = p;
                  indfound = option_index;
                }
-             else
+             else if (long_only
+                      || pfound->has_arg != p->has_arg
+                      || pfound->flag != p->flag
+                      || pfound->val != p->val)
                /* Second or later nonexact match found.  */
                ambig = 1;
            }
@@ -1028,6 +1031,8 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
                    return optstring[0] == ':' ? ':' : '?';
                  }
              }
+           else
+             d->optarg = NULL;
            d->__nextchar += strlen (d->__nextchar);
            if (longind != NULL)
              *longind = option_index;