changeset 15358:93a104b6dce4

getopt: handle W; without long options in getopt This reverts commit cbf381169705782b144b2733798a62c11aa473a5, in favor of the upstream glibc fix (commit 01636b214) plus a C89 fix. [BZ #12922] * lib/getopt.c (_getopt_internal_r): When "W;" is in short options but no long options are defined, just return 'W'. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Thu, 07 Jul 2011 08:54:11 -0600
parents c155eaad308b
children be44fb90ec88
files ChangeLog lib/getopt.c
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jul 07 13:14:37 2011 +0200
+++ b/ChangeLog	Thu Jul 07 08:54:11 2011 -0600
@@ -1,3 +1,9 @@
+2011-07-07  Ulrich Drepper  <drepper@gmail.com>
+
+	getopt: handle W; without long options in getopt [BZ #12922]
+	* lib/getopt.c (_getopt_internal_r): When "W;" is in short options
+	but no long options are defined, just return 'W'.
+
 2011-07-07  Bruno Haible  <bruno@clisp.org>
 
 	Avoid literal tabs.
--- a/lib/getopt.c	Thu Jul 07 13:14:37 2011 +0200
+++ b/lib/getopt.c	Thu Jul 07 08:54:11 2011 -0600
@@ -829,7 +829,7 @@
         return '?';
       }
     /* Convenience. Treat POSIX -W foo same as long option --foo */
-    if (temp[0] == 'W' && temp[1] == ';' && longopts)
+    if (temp[0] == 'W' && temp[1] == ';')
       {
         char *nameend;
         const struct option *p;
@@ -839,6 +839,9 @@
         int indfound = 0;
         int option_index;
 
+        if (longopts == NULL)
+          goto no_longs;
+
         /* This is an option that requires an argument.  */
         if (*d->__nextchar != '\0')
           {
@@ -1046,8 +1049,10 @@
               }
             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] == ':')
       {