* posix/getopt_init.c (__getopt_clean_environment): Avoid making
	the strncmp calls most of the time by testing for '_' as the first
	character of the name.
This commit is contained in:
Ulrich Drepper 2001-08-11 05:32:47 +00:00
parent c020d48c6e
commit 6ae9b99ef2
2 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,9 @@
2001-08-10 Ulrich Drepper <drepper@redhat.com> 2001-08-10 Ulrich Drepper <drepper@redhat.com>
* posix/getopt_init.c (__getopt_clean_environment): Avoid making
the strncmp calls most of the time by testing for '_' as the first
character of the name.
* elf/dl-open.c (add_to_global): Remove stale comment. * elf/dl-open.c (add_to_global): Remove stale comment.
* elf/dl-load.c (fillin_rpath): In SUID binaries, don't mark * elf/dl-load.c (fillin_rpath): In SUID binaries, don't mark

View File

@ -1,5 +1,5 @@
/* Perform additional initialization for getopt functions in GNU libc. /* Perform additional initialization for getopt functions in GNU libc.
Copyright (C) 1997, 1998 Free Software Foundation, Inc. Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
@ -45,7 +45,7 @@ __getopt_clean_environment (char **env)
of file name wildcard expansion and therefore should not be of file name wildcard expansion and therefore should not be
considered as options. */ considered as options. */
static const char envvar_tail[] = "_GNU_nonoption_argv_flags_="; static const char envvar_tail[] = "_GNU_nonoption_argv_flags_=";
char var[100]; char var[50];
char *cp, **ep; char *cp, **ep;
size_t len; size_t len;
@ -54,11 +54,13 @@ __getopt_clean_environment (char **env)
cp = memcpy (&var[sizeof (var) - sizeof (envvar_tail)], envvar_tail, cp = memcpy (&var[sizeof (var) - sizeof (envvar_tail)], envvar_tail,
sizeof (envvar_tail)); sizeof (envvar_tail));
cp = _itoa_word (__getpid (), cp, 10, 0); cp = _itoa_word (__getpid (), cp, 10, 0);
*--cp = '_'; /* Note: we omit adding the leading '_' since we explicitly test for
it before calling strncmp. */
len = (var + sizeof (var) - 1) - cp; len = (var + sizeof (var) - 1) - cp;
for (ep = env; *ep != NULL; ++ep) for (ep = env; *ep != NULL; ++ep)
if (!strncmp (*ep, cp, len)) if ((*ep)[0] == '_'
&& __builtin_expect (strncmp (*ep + 1, cp, len) == 0, 0))
{ {
/* Found it. Store this pointer and move later ones back. */ /* Found it. Store this pointer and move later ones back. */
char **dp = ep; char **dp = ep;