]> Savannah Git Hosting - gnulib.git/commitdiff
getopt: remove USE_NONOPTION_FLAGS
authorZack Weinberg <zackw@panix.com>
Thu, 6 Apr 2017 18:14:13 +0000 (11:14 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 6 Apr 2017 22:42:02 +0000 (15:42 -0700)
getopt includes code to parse an environment variable named
_XXX_GNU_nonoption_argv_flags_ (where XXX is the current process's PID
in decimal); but all of it has been #ifdefed out since 2001, with no
official way to turn it back on.

According to commentary in glibc's config.h.in, bash version 2.0
set this environment variable to indicate argv elements that were
the result of glob expansion and therefore should not be treated
as options, but the feature was "disabled later" because "it
caused problems".  According to bash's CHANGES file, "later" was
release 2.01; it gives no more detail about what the problems
were.

Version 2.0 of bash was released on the last day of 1996, and version
2.01 in June of 1997.  Twenty years later, I think it is safe to
assume that this environment variable isn't coming back.

* lib/getopt_int.h: Remove all #ifdef USE_NONOPTION_FLAGS blocks.
* lib/getopt.c: Likewise. Also remove SWAP_FLAGS and the
__libc_argc and __libc_argv externs, which were only used by

ChangeLog
lib/getopt.c
lib/getopt_int.h

index 6a753fc34ddc86a8f943e13d655ae57bdb90bf9b..0e51f1d5ac500f8d60264da4c752f7bb5f15548f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,30 @@
 2017-04-06  Zack Weinberg  <zackw@panix.com>
 
+       getopt: remove USE_NONOPTION_FLAGS
+
+       getopt includes code to parse an environment variable named
+       _XXX_GNU_nonoption_argv_flags_ (where XXX is the current process's PID
+       in decimal); but all of it has been #ifdefed out since 2001, with no
+       official way to turn it back on.
+
+       According to commentary in glibc's config.h.in, bash version 2.0
+       set this environment variable to indicate argv elements that were
+       the result of glob expansion and therefore should not be treated
+       as options, but the feature was "disabled later" because "it
+       caused problems".  According to bash's CHANGES file, "later" was
+       release 2.01; it gives no more detail about what the problems
+       were.
+
+       Version 2.0 of bash was released on the last day of 1996, and version
+       2.01 in June of 1997.  Twenty years later, I think it is safe to
+       assume that this environment variable isn't coming back.
+
+       * lib/getopt_int.h: Remove all #ifdef USE_NONOPTION_FLAGS blocks.
+       * lib/getopt.c: Likewise. Also remove SWAP_FLAGS and the
+       __libc_argc and __libc_argv externs, which were only used by
+       #ifdef USE_NONOPTION_FLAGS blocks.
+
+
        getopt: tabify, in preparation for merge with glibc
 
        glibc sticks to the GNU default of indenting with a mix of
index 51523f7d13808b4521cbc491ea6d4c5335bbdcc3..157a737f9e009e3fb718237fd0747b7df2b2e892 100644 (file)
@@ -101,36 +101,6 @@ static struct _getopt_data getopt_data;
 extern char *getenv ();
 #endif
 \f
-#ifdef _LIBC
-/* Stored original parameters.
-   XXX This is no good solution.  We should rather copy the args so
-   that we can compare them later.  But we must not use malloc(3).  */
-extern int __libc_argc;
-extern char **__libc_argv;
-
-/* Bash 2.0 gives us an environment variable containing flags
-   indicating ARGV elements that should not be considered arguments.  */
-
-# ifdef USE_NONOPTION_FLAGS
-/* Defined in getopt_init.c  */
-extern char *__getopt_nonoption_flags;
-# endif
-
-# ifdef USE_NONOPTION_FLAGS
-#  define SWAP_FLAGS(ch1, ch2) \
-  if (d->__nonoption_flags_len > 0)                                          \
-    {                                                                        \
-      char __tmp = __getopt_nonoption_flags[ch1];                            \
-      __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2];         \
-      __getopt_nonoption_flags[ch2] = __tmp;                                 \
-    }
-# else
-#  define SWAP_FLAGS(ch1, ch2)
-# endif
-#else  /* !_LIBC */
-# define SWAP_FLAGS(ch1, ch2)
-#endif /* _LIBC */
-
 /* Exchange two adjacent subsequences of ARGV.
    One subsequence is elements [first_nonopt,last_nonopt)
    which contains all the non-options that have been skipped so far.
@@ -153,28 +123,6 @@ exchange (char **argv, struct _getopt_data *d)
      It leaves the longer segment in the right place overall,
      but it consists of two parts that need to be swapped next.  */
 
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  /* First make sure the handling of the '__getopt_nonoption_flags'
-     string can work normally.  Our top argument must be in the range
-     of the string.  */
-  if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
-    {
-      /* We must extend the array.  The user plays games with us and
-        presents new arguments.  */
-      char *new_str = malloc (top + 1);
-      if (new_str == NULL)
-       d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
-      else
-       {
-         memset (__mempcpy (new_str, __getopt_nonoption_flags,
-                            d->__nonoption_flags_max_len),
-                 '\0', top + 1 - d->__nonoption_flags_max_len);
-         d->__nonoption_flags_max_len = top + 1;
-         __getopt_nonoption_flags = new_str;
-       }
-    }
-#endif
-
   while (top > middle && middle > bottom)
     {
       if (top - middle > middle - bottom)
@@ -189,7 +137,6 @@ exchange (char **argv, struct _getopt_data *d)
              tem = argv[bottom + i];
              argv[bottom + i] = argv[top - (middle - bottom) + i];
              argv[top - (middle - bottom) + i] = tem;
-             SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
            }
          /* Exclude the moved bottom segment from further swapping.  */
          top -= len;
@@ -206,7 +153,6 @@ exchange (char **argv, struct _getopt_data *d)
              tem = argv[bottom + i];
              argv[bottom + i] = argv[middle + i];
              argv[middle + i] = tem;
-             SWAP_FLAGS (bottom + i, middle + i);
            }
          /* Exclude the moved top segment from further swapping.  */
          bottom += len;
@@ -253,36 +199,6 @@ _getopt_initialize (int argc _GL_UNUSED,
   else
     d->__ordering = PERMUTE;
 
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  if (!d->__posixly_correct
-      && argc == __libc_argc && argv == __libc_argv)
-    {
-      if (d->__nonoption_flags_max_len == 0)
-       {
-         if (__getopt_nonoption_flags == NULL
-             || __getopt_nonoption_flags[0] == '\0')
-           d->__nonoption_flags_max_len = -1;
-         else
-           {
-             const char *orig_str = __getopt_nonoption_flags;
-             int len = d->__nonoption_flags_max_len = strlen (orig_str);
-             if (d->__nonoption_flags_max_len < argc)
-               d->__nonoption_flags_max_len = argc;
-             __getopt_nonoption_flags =
-               (char *) malloc (d->__nonoption_flags_max_len);
-             if (__getopt_nonoption_flags == NULL)
-               d->__nonoption_flags_max_len = -1;
-             else
-               memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
-                       '\0', d->__nonoption_flags_max_len - len);
-           }
-       }
-      d->__nonoption_flags_len = d->__nonoption_flags_max_len;
-    }
-  else
-    d->__nonoption_flags_len = 0;
-#endif
-
   return optstring;
 }
 \f
@@ -367,17 +283,8 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
   if (optstring[0] == ':')
     print_errors = 0;
 
-  /* Test whether ARGV[optind] points to a non-option argument.
-     Either it does not have option syntax, or there is an environment flag
-     from the shell indicating it is not an option.  The later information
-     is only used when the used in the GNU libc.  */
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
-                     || (d->optind < d->__nonoption_flags_len                \
-                         && __getopt_nonoption_flags[d->optind] == '1'))
-#else
-# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
-#endif
+  /* Test whether ARGV[optind] points to a non-option argument.  */
+#define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
 
   if (d->__nextchar == NULL || *d->__nextchar == '\0')
     {
index 6fc131b633baa18eee470f61a791a161eb89dcbc..5a5528c626a4acdaa315b812a2e8f736c6e397b6 100644 (file)
@@ -104,11 +104,6 @@ struct _getopt_data
 
   int __first_nonopt;
   int __last_nonopt;
-
-#if defined _LIBC && defined USE_NONOPTION_FLAGS
-  int __nonoption_flags_max_len;
-  int __nonoption_flags_len;
-#endif
 };
 
 /* The initializer is necessary to set OPTIND and OPTERR to their