mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 06:16:38 +00:00
Fix environment variable handling. The (optional) envp argument to main() shall not contain strings of the form "=C:=C:\directory\".
svn path=/trunk/; revision=8280
This commit is contained in:
parent
184c8d2fba
commit
b3e3acc784
1 changed files with 14 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: environ.c,v 1.6 2003/12/24 23:20:08 sedwards Exp $
|
||||
/* $Id: environ.c,v 1.7 2004/02/21 08:02:49 tamlin Exp $
|
||||
*
|
||||
* dllmain.c
|
||||
*
|
||||
|
@ -43,7 +43,7 @@ int *__p__commode(void) // not exported by NTDLL
|
|||
int BlockEnvToEnviron(void)
|
||||
{
|
||||
char * ptr, * ptr2;
|
||||
int i, len;
|
||||
int i, count;
|
||||
|
||||
DPRINT("BlockEnvToEnviron()\n");
|
||||
|
||||
|
@ -57,18 +57,25 @@ int BlockEnvToEnviron(void)
|
|||
DPRINT("GetEnvironmentStringsA() returnd NULL\n");
|
||||
return -1;
|
||||
}
|
||||
len = 0;
|
||||
count = 0;
|
||||
while (*ptr2) {
|
||||
len++;
|
||||
/* skip current directory of the form "=C:=C:\directory\" */
|
||||
if (*ptr2 != '=') {
|
||||
count++;
|
||||
}
|
||||
ptr2 += strlen(ptr2) + 1;
|
||||
}
|
||||
_environ = malloc((len + 1) * sizeof(char*));
|
||||
_environ = malloc((count + 1) * sizeof(char*));
|
||||
if (_environ == NULL) {
|
||||
FreeEnvironmentStringsA(ptr);
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < len && *ptr; i++) {
|
||||
_environ[i] = ptr;
|
||||
i = 0;
|
||||
while (i < count && *ptr) {
|
||||
if (*ptr != '=') {
|
||||
_environ[i] = ptr;
|
||||
++i;
|
||||
}
|
||||
ptr += strlen(ptr) + 1;
|
||||
}
|
||||
_environ[i] = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue