Revert last patch.

svn path=/trunk/; revision=3186
This commit is contained in:
Eric Kohl 2002-07-06 17:38:06 +00:00
parent 8fc03ec0f6
commit 5e114ab271

View file

@ -1,4 +1,4 @@
/* $Id: env.c,v 1.14 2002/07/05 17:23:05 ekohl Exp $ /* $Id: env.c,v 1.15 2002/07/06 17:38:06 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -180,6 +180,7 @@ copy:
dst_max--; dst_max--;
src_len--; src_len--;
} }
Destination->Length = (d - Destination->Buffer) * sizeof(WCHAR); Destination->Length = (d - Destination->Buffer) * sizeof(WCHAR);
if (Length != NULL) if (Length != NULL)
*Length = Destination->Length; *Length = Destination->Length;
@ -187,7 +188,7 @@ copy:
Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0; Destination->Buffer[Destination->Length / sizeof(WCHAR)] = 0;
DPRINT("Destination %wZ\n", Destination); DPRINT("Destination %wZ\n", Destination);
return Status; return(Status);
} }
@ -218,7 +219,7 @@ RtlSetEnvironmentVariable(PWSTR *Environment,
PUNICODE_STRING Value) PUNICODE_STRING Value)
{ {
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
UNICODE_STRING var, ExpandedValue; UNICODE_STRING var;
int hole_len, new_len, env_len = 0; int hole_len, new_len, env_len = 0;
WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0; WCHAR *new_env = 0, *env_end = 0, *wcs, *env, *val = 0, *tail = 0, *hole = 0;
PWSTR head = NULL; PWSTR head = NULL;
@ -283,45 +284,11 @@ RtlSetEnvironmentVariable(PWSTR *Environment,
} }
found: found:
/* Perform inline replacement if Value references existing vars */ if (Value->Length > 0)
/* ex: SET PATH=C:\MinGW\Bin;%PATH% */
ExpandedValue.MaximumLength = (env_len + Value->Length) * 2 * sizeof(WCHAR);
ExpandedValue.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
ExpandedValue.MaximumLength + 1);
if (ExpandedValue.Buffer == NULL)
{
if (Environment == NULL)
{
RtlReleasePebLock();
}
return(STATUS_INSUFFICIENT_RESOURCES);
}
ExpandedValue.Length = 0;
ExpandedValue.Buffer[0] = (WCHAR)'\0';
Status = RtlExpandEnvironmentStrings_U(env,
Value,
&ExpandedValue,
NULL);
if (!NT_SUCCESS(Status))
{
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandedValue.Buffer);
if (Environment == NULL)
{
RtlReleasePebLock();
}
return(Status);
}
if (ExpandedValue.Length > 0)
{ {
hole_len = tail - hole; hole_len = tail - hole;
/* calculate new environment size */ /* calculate new environment size */
new_size = ExpandedValue.Length + sizeof(WCHAR); new_size = Value->Length + sizeof(WCHAR);
/* adding new variable */ /* adding new variable */
if (f) if (f)
new_size += Name->Length + sizeof(WCHAR); new_size += Name->Length + sizeof(WCHAR);
@ -345,9 +312,6 @@ found:
NULL); NULL);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandedValue.Buffer);
if (Environment == NULL) if (Environment == NULL)
{ {
RtlReleasePebLock(); RtlReleasePebLock();
@ -367,9 +331,6 @@ found:
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandedValue.Buffer);
if (Environment == NULL) if (Environment == NULL)
{ {
RtlReleasePebLock(); RtlReleasePebLock();
@ -428,9 +389,9 @@ found:
/* copy value */ /* copy value */
memmove(hole, memmove(hole,
ExpandedValue.Buffer, Value->Buffer,
ExpandedValue.Length); Value->Length);
hole += ExpandedValue.Length / sizeof(WCHAR); hole += Value->Length / sizeof(WCHAR);
*hole = 0; *hole = 0;
} }
else else
@ -448,9 +409,6 @@ found:
} }
} }
RtlFreeHeap(RtlGetProcessHeap(),
0,
ExpandedValue.Buffer);
if (Environment == NULL) if (Environment == NULL)
{ {
RtlReleasePebLock(); RtlReleasePebLock();
@ -483,7 +441,7 @@ RtlQueryEnvironmentVariable_U(PWSTR Environment,
} }
if (Environment == NULL) if (Environment == NULL)
return STATUS_VARIABLE_NOT_FOUND; return(STATUS_VARIABLE_NOT_FOUND);
Value->Length = 0; Value->Length = 0;
if (SysEnvUsed == TRUE) if (SysEnvUsed == TRUE)
@ -522,7 +480,7 @@ RtlQueryEnvironmentVariable_U(PWSTR Environment,
if (SysEnvUsed == TRUE) if (SysEnvUsed == TRUE)
RtlReleasePebLock(); RtlReleasePebLock();
return Status; return(Status);
} }
} }
wcs++; wcs++;
@ -532,7 +490,7 @@ RtlQueryEnvironmentVariable_U(PWSTR Environment,
RtlReleasePebLock(); RtlReleasePebLock();
DPRINT("Return STATUS_VARIABLE_NOT_FOUND\n"); DPRINT("Return STATUS_VARIABLE_NOT_FOUND\n");
return STATUS_VARIABLE_NOT_FOUND; return(STATUS_VARIABLE_NOT_FOUND);
} }
/* EOF */ /* EOF */