about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-07-06 21:27:14 -0400
committerAndreas Schwab <schwab@redhat.com>2011-07-21 12:17:04 +0200
commit77b2540f78e4c97ffded2c0600012cc48c4670fd (patch)
tree717bf5fdb7efbbea2c9cee806745ab805aef0a22
parentaf6207d5391d434d6f2951da4c8f57d1f3a2a762 (diff)
downloadglibc-77b2540f78e4c97ffded2c0600012cc48c4670fd.tar.gz
glibc-77b2540f78e4c97ffded2c0600012cc48c4670fd.tar.xz
glibc-77b2540f78e4c97ffded2c0600012cc48c4670fd.zip
Handle W; without long options in getopt
(cherry picked from commit 01636b2140cd1281202b89f7103249ed598065c4)
-rw-r--r--ChangeLog6
-rw-r--r--posix/getopt.c9
2 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b11f5ee012..4d7e1ba669 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-07-06  Ulrich Drepper  <drepper@gmail.com>
+
+	[BZ #12922]
+	* posix/getopt.c (_getopt_internal_r): When "W;" is in short options
+	but no long options are defined, just return 'W'.
+
 2011-06-22  Marek Polacek  <mpolacek@redhat.com>
 
 	[BZ #9696]
diff --git a/posix/getopt.c b/posix/getopt.c
index db89abf6a7..3fa5a4d6d1 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -871,6 +871,9 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
     /* Convenience. Treat POSIX -W foo same as long option --foo */
     if (temp[0] == 'W' && temp[1] == ';')
       {
+	if (longopts == NULL)
+	  goto no_longs;
+
 	char *nameend;
 	const struct option *p;
 	const struct option *pfound = NULL;
@@ -1086,8 +1089,10 @@ _getopt_internal_r (int argc, char *const *argv, const char *optstring,
 	      }
 	    return pfound->val;
 	  }
-	  d->__nextchar = NULL;
-	  return 'W';	/* Let the application handle it.   */
+
+      no_longs:
+	d->__nextchar = NULL;
+	return 'W';	/* Let the application handle it.   */
       }
     if (temp[1] == ':')
       {