* environ.cc (getearly): Use GetEnvironmentVariable and cmalloc instead of

GetEnvironmentStrings.
(environ_init): Revert rawenv stuff.
This commit is contained in:
Christopher Faylor 2006-04-21 21:34:38 +00:00
parent 478e8b1569
commit 3a83d3a849
3 changed files with 27 additions and 26 deletions

View File

@ -1,3 +1,10 @@
2006-04-21 Pierre Humblet Pierre.Humblet@ieee.org
Christopher Faylor <cgf@timesys.com>
* environ.cc (getearly): Use GetEnvironmentVariable and cmalloc instead
of GetEnvironmentStrings.
(environ_init): Revert rawenv stuff.
2006-04-21 Christopher Faylor <cgf@timesys.com> 2006-04-21 Christopher Faylor <cgf@timesys.com>
* environ.cc (rawenv): Make this variable a file-scope static. * environ.cc (rawenv): Make this variable a file-scope static.

View File

@ -30,6 +30,7 @@ enum cygheap_types
HEAP_1_BUF, HEAP_1_BUF,
HEAP_1_EXEC, HEAP_1_EXEC,
HEAP_1_MAX = 100, HEAP_1_MAX = 100,
HEAP_2_STR,
HEAP_MMAP = 200 HEAP_MMAP = 200
}; };

View File

@ -220,25 +220,26 @@ my_findenv (const char *name, int *offset)
return NULL; return NULL;
} }
static NO_COPY char *rawenv;
/* Primitive getenv before the environment is built. */ /* Primitive getenv before the environment is built. */
static char __stdcall * static char __stdcall *
getearly (const char * name, int *offset __attribute__ ((unused))) getearly (const char * name, int *)
{ {
char *p; char *ret;
char **ptr; char **ptr;
int len = strlen (name); int len;
if (spawn_info && (ptr = spawn_info->moreinfo->envp)) if (spawn_info && (ptr = spawn_info->moreinfo->envp))
{
len = strlen (name);
for (; *ptr; ptr++) for (; *ptr; ptr++)
if (strncasematch (name, *ptr, len) && *ptr[len] == '=') if (strncasematch (name, *ptr, len) && *ptr[len] == '=')
return *ptr + len + 1; return *ptr + len + 1;
else if (rawenv || (rawenv = GetEnvironmentStrings ())) }
for (p = rawenv; *p; p = strchr (p, '\0') + 1) else if ((len = GetEnvironmentVariable (name, NULL, 0))
if (strncasematch (name, p, len) && p[len] == '=') && (ret = (char *) cmalloc (HEAP_2_STR, len))
return p + len + 1; && GetEnvironmentVariable (name, ret, len))
return ret;
return NULL; return NULL;
} }
@ -733,6 +734,7 @@ regopt (const char *name)
void void
environ_init (char **envp, int envc) environ_init (char **envp, int envc)
{ {
char *rawenv;
int i; int i;
char *p; char *p;
char *newp; char *newp;
@ -781,27 +783,19 @@ environ_init (char **envp, int envc)
cfree (p); cfree (p);
} }
envp_passed_in = 1; envp_passed_in = 1;
if (rawenv)
{
FreeEnvironmentStrings (rawenv);
rawenv = NULL;
}
goto out; goto out;
} }
/* Allocate space for environment + trailing NULL + CYGWIN env. */ /* Allocate space for environment + trailing NULL + CYGWIN env. */
lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *)); lastenviron = envp = (char **) malloc ((4 + (envc = 100)) * sizeof (char *));
if (!rawenv)
{
rawenv = GetEnvironmentStrings (); rawenv = GetEnvironmentStrings ();
if (!rawenv) if (!rawenv)
{ {
system_printf ("GetEnvironmentStrings returned NULL, %E"); system_printf ("GetEnvironmentStrings returned NULL, %E");
return; return;
} }
} debug_printf ("GetEnvironmentStrings returned %p - \"%s\"", rawenv, rawenv);
debug_printf ("rawenv %p - \"%s\"", rawenv, rawenv);
/* Current directory information is recorded as variables of the /* Current directory information is recorded as variables of the
form "=X:=X:\foo\bar; these must be changed into something legal form "=X:=X:\foo\bar; these must be changed into something legal
@ -831,7 +825,6 @@ environ_init (char **envp, int envc)
envp[i++] = strdup (cygterm); envp[i++] = strdup (cygterm);
envp[i] = NULL; envp[i] = NULL;
FreeEnvironmentStrings (rawenv); FreeEnvironmentStrings (rawenv);
rawenv = NULL;
out: out:
findenv_func = (char * (*)(const char*, int*)) my_findenv; findenv_func = (char * (*)(const char*, int*)) my_findenv;