about summary refs log tree commit diff
path: root/posix
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2010-04-07 17:16:27 -0700
committerUlrich Drepper <drepper@redhat.com>2010-04-07 17:16:27 -0700
commitaa7f642769abcfbce658aeaaffdc9fb4790cd905 (patch)
treeea9fe568ed20f3a3aefae5ff33f0831fc5d161ea /posix
parent22ef35456ea0b36e09f3241043f894eb71d2c9da (diff)
downloadglibc-aa7f642769abcfbce658aeaaffdc9fb4790cd905.tar.gz
glibc-aa7f642769abcfbce658aeaaffdc9fb4790cd905.tar.xz
glibc-aa7f642769abcfbce658aeaaffdc9fb4790cd905.zip
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.
Diffstat (limited to 'posix')
-rw-r--r--posix/getopt.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/posix/getopt.c b/posix/getopt.c
index 88acff0e2f..01c1071ecb 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;