aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/environ.cc
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2000-10-19 00:45:39 +0000
committerDJ Delorie <dj@redhat.com>2000-10-19 00:45:39 +0000
commit6e8f36bc43a54e6d6d21528acfe6f92d07781a9d (patch)
tree0fd61de3446c5bef3f82bed4c4663c9ec9f0e219 /winsup/cygwin/environ.cc
parentb8cb783f28eedbc327ca0d9bc4ebde6227d9d9e1 (diff)
downloadnewlib-6e8f36bc43a54e6d6d21528acfe6f92d07781a9d.zip
newlib-6e8f36bc43a54e6d6d21528acfe6f92d07781a9d.tar.gz
newlib-6e8f36bc43a54e6d6d21528acfe6f92d07781a9d.tar.bz2
* dcrt0.cc (dll_crt0_1): init cygcwd before forkee branch
* environ.cc (conv_start_chars): Cache a table of "first characters" for environment variables needing conversion. (getwinenv): Use it. (environ_init): Create it, also check first chars for TERM and CYGWIN. * path.cc: Use lookup table for case insensitive comparisons.
Diffstat (limited to 'winsup/cygwin/environ.cc')
-rw-r--r--winsup/cygwin/environ.cc22
1 files changed, 19 insertions, 3 deletions
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 31f87ad..b93d7e6 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -61,6 +61,8 @@ static win_env conv_envvars[] =
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
};
+static unsigned char conv_start_chars[256] = {0};
+
void
win_env::add_cache (const char *in_posix, const char *in_native)
{
@@ -91,6 +93,9 @@ win_env::add_cache (const char *in_posix, const char *in_native)
win_env * __stdcall
getwinenv (const char *env, const char *in_posix)
{
+ if (!conv_start_chars[(unsigned char)*env])
+ return NULL;
+
for (int i = 0; conv_envvars[i].name != NULL; i++)
if (strncasematch (env, conv_envvars[i].name, conv_envvars[i].namelen))
{
@@ -528,6 +533,17 @@ environ_init (char **envp, int envc)
bool envp_passed_in;
static char cygterm[] = "TERM=cygwin";
+ static int initted = 0;
+ if (!initted)
+ {
+ for (int i = 0; conv_envvars[i].name != NULL; i++)
+ {
+ conv_start_chars[tolower(conv_envvars[i].name[0])] = 1;
+ conv_start_chars[toupper(conv_envvars[i].name[0])] = 1;
+ }
+ initted = 1;
+ }
+
regopt ("default");
if (myself->progname[0])
regopt (myself->progname);
@@ -571,11 +587,11 @@ environ_init (char **envp, int envc)
eq = strchr (newp, '\0');
if (!parent_alive)
ucenv (newp, eq);
- if (strncmp (newp, "TERM=", 5) == 0)
+ if (*newp == 'T' && strncmp (newp, "TERM=", 5) == 0)
sawTERM = 1;
- if (strncmp (newp, "CYGWIN=", sizeof("CYGWIN=") - 1) == 0)
+ if (*newp == 'C' && strncmp (newp, "CYGWIN=", sizeof("CYGWIN=") - 1) == 0)
parse_options (newp + sizeof("CYGWIN=") - 1);
- if (*eq)
+ if (*eq && conv_start_chars[(unsigned char)envp[i][0]])
posify (envp + i, *++eq ? eq : --eq);
debug_printf ("%s", envp[i]);
}