- RtlSetEnvironmentVariable: To delete a variable, it is necessary to pass a NULL...
authorJeffrey Morlan <mrnobo1024@yahoo.com>
Tue, 26 Aug 2008 15:28:29 +0000 (15:28 +0000)
committerJeffrey Morlan <mrnobo1024@yahoo.com>
Tue, 26 Aug 2008 15:28:29 +0000 (15:28 +0000)
- SetEnvironmentVariable(A|W): When given a NULL value, pass NULL to RtlSetEnvironmentVariable.
- cmd_set: When given an empty value, pass NULL to SetEnvironmentVariable.

svn path=/trunk/; revision=35672

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

index e04211a..115b837 100644 (file)
@@ -154,7 +154,7 @@ INT cmd_set (LPTSTR param)
                }
 
                *p++ = _T('\0');
-               if (!SetEnvironmentVariable(param, p))
+               if (!SetEnvironmentVariable(param, *p ? p : NULL))
                {
                        nErrorLevel = 1;
                        return 1;
index b5aa8c5..c4f0ee2 100644 (file)
@@ -193,18 +193,27 @@ SetEnvironmentVariableA (
                                      &VarName,
                                      TRUE);
 
-       RtlInitAnsiString (&VarValue,
-                          (LPSTR)lpValue);
-       RtlAnsiStringToUnicodeString (&VarValueU,
-                                     &VarValue,
-                                     TRUE);
+       if (lpValue)
+       {
+               RtlInitAnsiString (&VarValue,
+                                  (LPSTR)lpValue);
+               RtlAnsiStringToUnicodeString (&VarValueU,
+                                             &VarValue,
+                                             TRUE);
 
-       Status = RtlSetEnvironmentVariable (NULL,
-                                           &VarNameU,
-                                           &VarValueU);
+               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 @@ SetEnvironmentVariableW (
        RtlInitUnicodeString (&VarName,
                              lpName);
 
-       RtlInitUnicodeString (&VarValue,
-                             lpValue);
+       if (lpValue)
+       {
+               RtlInitUnicodeString (&VarValue,
+                                     lpValue);
+
+               Status = RtlSetEnvironmentVariable (NULL,
+                                                   &VarName,
+                                                   &VarValue);
+       }
+       else
+       {
+               Status = RtlSetEnvironmentVariable (NULL,
+                                                   &VarName,
+                                                   NULL);
+       }
 
-       Status = RtlSetEnvironmentVariable (NULL,
-                                           &VarName,
-                                           &VarValue);
        if (!NT_SUCCESS(Status))
        {
                SetLastErrorByStatus (Status);
index 2e437f7..86a418e 100644 (file)
@@ -355,7 +355,7 @@ RtlSetEnvironmentVariable(PWSTR *Environment,
    }
 
 found:
-   if (Value != NULL && Value->Length > 0)
+   if (Value != NULL)
    {
       hole_len = tail - hole;
       /* calculate new environment size */