diff options
author | Eric Blake <ebb9@byu.net> | 2010-04-07 17:16:27 -0700 |
---|---|---|
committer | Petr Baudis <pasky@ucw.cz> | 2010-05-12 03:21:14 +0200 |
commit | 443a33d8042f4084d4d1f40a5b973a19bcae9a23 (patch) | |
tree | c717feeb87e39185ba23667f73b169cb08833e9a | |
parent | 52ade99fe57673eccffbcd71dea61692c424930d (diff) | |
download | glibc-443a33d8042f4084d4d1f40a5b973a19bcae9a23.zip glibc-443a33d8042f4084d4d1f40a5b973a19bcae9a23.tar.gz glibc-443a33d8042f4084d4d1f40a5b973a19bcae9a23.tar.bz2 |
Fix -W with optional parameters in getopt.
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)
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | posix/getopt.c | 7 |
2 files changed, 12 insertions, 1 deletions
@@ -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] diff --git a/posix/getopt.c b/posix/getopt.c index 88acff0..01c1071 100644 --- a/posix/getopt.c +++ b/posix/getopt.c @@ -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; |