From 6e8f36bc43a54e6d6d21528acfe6f92d07781a9d Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Thu, 19 Oct 2000 00:45:39 +0000 Subject: * 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. --- winsup/cygwin/environ.cc | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'winsup/cygwin/environ.cc') diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc index 31f87ad2d..b93d7e661 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]); } -- cgit v1.2.3