[ros-diffs] [jmorlan] 35672: - RtlSetEnvironmentVariable: To delete a variable, it is necessary to pass a NULL pointer as the value; passing an empty string should create an empty variable. Remove Value->Length > 0 check. - SetEnvironmentVariable(A|W): When given a NULL value, pass NULL to RtlSetEnvironmentVariable. - cmd_set: When given an empty value, pass NULL to SetEnvironmentVariable.

jmorlan at svn.reactos.org jmorlan at svn.reactos.org
Tue Aug 26 17:28:30 CEST 2008


Author: jmorlan
Date: Tue Aug 26 10:28:29 2008
New Revision: 35672

URL: http://svn.reactos.org/svn/reactos?rev=35672&view=rev
Log:
- RtlSetEnvironmentVariable: To delete a variable, it is necessary to pass a NULL pointer as the value; passing an empty string should create an empty variable. Remove Value->Length > 0 check.
- SetEnvironmentVariable(A|W): When given a NULL value, pass NULL to RtlSetEnvironmentVariable.
- cmd_set: When given an empty value, pass NULL to SetEnvironmentVariable.

Modified:
    trunk/reactos/base/shell/cmd/set.c
    trunk/reactos/dll/win32/kernel32/misc/env.c
    trunk/reactos/lib/rtl/env.c

Modified: trunk/reactos/base/shell/cmd/set.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/set.c?rev=35672&r1=35671&r2=35672&view=diff
==============================================================================
--- trunk/reactos/base/shell/cmd/set.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/set.c [iso-8859-1] Tue Aug 26 10:28:29 2008
@@ -154,7 +154,7 @@
 		}
 
 		*p++ = _T('\0');
-		if (!SetEnvironmentVariable(param, p))
+		if (!SetEnvironmentVariable(param, *p ? p : NULL))
 		{
 			nErrorLevel = 1;
 			return 1;

Modified: trunk/reactos/dll/win32/kernel32/misc/env.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/env.c?rev=35672&r1=35671&r2=35672&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/env.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/env.c [iso-8859-1] Tue Aug 26 10:28:29 2008
@@ -193,18 +193,27 @@
 	                              &VarName,
 	                              TRUE);
 
-	RtlInitAnsiString (&VarValue,
-	                   (LPSTR)lpValue);
-	RtlAnsiStringToUnicodeString (&VarValueU,
-	                              &VarValue,
-	                              TRUE);
-
-	Status = RtlSetEnvironmentVariable (NULL,
-	                                    &VarNameU,
-	                                    &VarValueU);
-
+	if (lpValue)
+	{
+		RtlInitAnsiString (&VarValue,
+		                   (LPSTR)lpValue);
+		RtlAnsiStringToUnicodeString (&VarValueU,
+		                              &VarValue,
+		                              TRUE);
+
+		Status = RtlSetEnvironmentVariable (NULL,
+		                                    &VarNameU,
+		                                    &VarValueU);
+
+		RtlFreeUnicodeString (&VarValueU);
+	}
+	else
+	{
+		Status = RtlSetEnvironmentVariable (NULL,
+		                                    &VarNameU,
+		                                    NULL);
+	}
 	RtlFreeUnicodeString (&VarNameU);
-	RtlFreeUnicodeString (&VarValueU);
 
 	if (!NT_SUCCESS(Status))
 	{
@@ -235,12 +244,22 @@
 	RtlInitUnicodeString (&VarName,
 	                      lpName);
 
-	RtlInitUnicodeString (&VarValue,
-	                      lpValue);
-
-	Status = RtlSetEnvironmentVariable (NULL,
-	                                    &VarName,
-	                                    &VarValue);
+	if (lpValue)
+	{
+		RtlInitUnicodeString (&VarValue,
+		                      lpValue);
+
+		Status = RtlSetEnvironmentVariable (NULL,
+		                                    &VarName,
+		                                    &VarValue);
+	}
+	else
+	{
+		Status = RtlSetEnvironmentVariable (NULL,
+		                                    &VarName,
+		                                    NULL);
+	}
+
 	if (!NT_SUCCESS(Status))
 	{
 		SetLastErrorByStatus (Status);

Modified: trunk/reactos/lib/rtl/env.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/env.c?rev=35672&r1=35671&r2=35672&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/env.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/env.c [iso-8859-1] Tue Aug 26 10:28:29 2008
@@ -355,7 +355,7 @@
    }
 
 found:
-   if (Value != NULL && Value->Length > 0)
+   if (Value != NULL)
    {
       hole_len = tail - hole;
       /* calculate new environment size */



More information about the Ros-diffs mailing list