aboutsummaryrefslogtreecommitdiff
path: root/posix/getopt_init.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-03-29 16:58:58 -0400
committerZack Weinberg <zackw@panix.com>2017-04-07 07:45:53 -0400
commitbf079e19f50d64aa5e05b5e17ec29afab9aabb20 (patch)
tree20d692f78e56b933b229441f678604c3761058ac /posix/getopt_init.c
parente4e794841e3140875f2aa86b90e2ada3d61e1244 (diff)
downloadglibc-bf079e19f50d64aa5e05b5e17ec29afab9aabb20.zip
glibc-bf079e19f50d64aa5e05b5e17ec29afab9aabb20.tar.gz
glibc-bf079e19f50d64aa5e05b5e17ec29afab9aabb20.tar.bz2
getopt: remove USE_NONOPTION_FLAGS
glibc's implementation of 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 our 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. * config.h.in (USE_NONOPTION_FLAGS): Remove. * csu/init-first.c: Remove all #ifdef USE_NONOPTION_FLAGS blocks. * sysdeps/mach/hurd/i386/init-first.c: Likewise. * posix/getopt_int.h: Likewise. * posix/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. * posix/getopt_init.c: Remove file. * posix/Makefile (routines): Remove getopt_init. * include/getopt.h: Don't declare __getopt_initialize_environment. * manual/getopt.texi: Remove mention of USE_NONOPTION_FLAGS in a comment.
Diffstat (limited to 'posix/getopt_init.c')
-rw-r--r--posix/getopt_init.c74
1 files changed, 0 insertions, 74 deletions
diff --git a/posix/getopt_init.c b/posix/getopt_init.c
deleted file mode 100644
index 498b301..0000000
--- a/posix/getopt_init.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Perform additional initialization for getopt functions in GNU libc.
- Copyright (C) 1997-2017 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
- Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
-
-#ifdef USE_NONOPTION_FLAGS
-/* Attention: this file is *not* necessary when the GNU getopt functions
- are used outside the GNU libc. Some additional functionality of the
- getopt functions in GNU libc require this additional work. */
-
-#include <getopt.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <_itoa.h>
-
-/* Variable to synchronize work. */
-char *__getopt_nonoption_flags;
-
-
-/* Remove the environment variable "_<PID>_GNU_nonoption_argv_flags_" if
- it is still available. If the getopt functions are also used in the
- application it does not exist anymore since it was saved for the use
- in getopt. */
-void
-__getopt_clean_environment (char **env)
-{
- /* Bash 2.0 puts a special variable in the environment for each
- command it runs, specifying which ARGV elements are the results
- of file name wildcard expansion and therefore should not be
- considered as options. */
- static const char envvar_tail[] = "_GNU_nonoption_argv_flags_=";
- char var[50];
- char *cp, **ep;
- size_t len;
-
- /* Construct the "_<PID>_GNU_nonoption_argv_flags_=" string. We must
- not use `sprintf'. */
- cp = memcpy (&var[sizeof (var) - sizeof (envvar_tail)], envvar_tail,
- sizeof (envvar_tail));
- cp = _itoa_word (__getpid (), cp, 10, 0);
- /* Note: we omit adding the leading '_' since we explicitly test for
- it before calling strncmp. */
- len = (var + sizeof (var) - 1) - cp;
-
- for (ep = env; *ep != NULL; ++ep)
- if ((*ep)[0] == '_'
- && __builtin_expect (strncmp (*ep + 1, cp, len) == 0, 0))
- {
- /* Found it. Store this pointer and move later ones back. */
- char **dp = ep;
- __getopt_nonoption_flags = &(*ep)[len];
- do
- dp[0] = dp[1];
- while (*dp++);
- /* Continue the loop in case the name appears again. */
- }
-}
-#endif /* USE_NONOPTION_FLAGS */