Alexandre Julliard : kernel32: Append the user PATH value to the system one .

Alexandre Julliard julliard at winehq.org
Thu Jan 28 11:15:37 CST 2010


Module: wine
Branch: master
Commit: 6beb82e2d6cc400c97fc654c2f157c217c4f87e4
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6beb82e2d6cc400c97fc654c2f157c217c4f87e4

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Jan 28 14:53:24 2010 +0100

kernel32: Append the user PATH value to the system one.

---

 dlls/kernel32/process.c |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 993fa6e..1ef3e46 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -358,13 +358,20 @@ static BOOL build_initial_environment(void)
  */
 static void set_registry_variables( HANDLE hkey, ULONG type )
 {
+    static const WCHAR pathW[] = {'P','A','T','H'};
+    static const WCHAR sep[] = {';',0};
     UNICODE_STRING env_name, env_value;
     NTSTATUS status;
     DWORD size;
     int index;
     char buffer[1024*sizeof(WCHAR) + sizeof(KEY_VALUE_FULL_INFORMATION)];
+    WCHAR tmpbuf[1024];
+    UNICODE_STRING tmp;
     KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
 
+    tmp.Buffer = tmpbuf;
+    tmp.MaximumLength = sizeof(tmpbuf);
+
     for (index = 0; ; index++)
     {
         status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
@@ -376,24 +383,27 @@ static void set_registry_variables( HANDLE hkey, ULONG type )
         env_name.Buffer = info->Name;
         env_name.Length = env_name.MaximumLength = info->NameLength;
         env_value.Buffer = (WCHAR *)(buffer + info->DataOffset);
-        env_value.Length = env_value.MaximumLength = info->DataLength;
+        env_value.Length = info->DataLength;
+        env_value.MaximumLength = sizeof(buffer) - info->DataOffset;
         if (env_value.Length && !env_value.Buffer[env_value.Length/sizeof(WCHAR)-1])
             env_value.Length -= sizeof(WCHAR);  /* don't count terminating null if any */
         if (!env_value.Length) continue;
         if (info->Type == REG_EXPAND_SZ)
         {
-            WCHAR buf_expanded[1024];
-            UNICODE_STRING env_expanded;
-            env_expanded.Length = env_expanded.MaximumLength = sizeof(buf_expanded);
-            env_expanded.Buffer=buf_expanded;
-            status = RtlExpandEnvironmentStrings_U(NULL, &env_value, &env_expanded, NULL);
-            if (status == STATUS_SUCCESS || status == STATUS_BUFFER_OVERFLOW)
-                RtlSetEnvironmentVariable( NULL, &env_name, &env_expanded );
+            status = RtlExpandEnvironmentStrings_U( NULL, &env_value, &tmp, NULL );
+            if (status != STATUS_SUCCESS && status != STATUS_BUFFER_OVERFLOW) continue;
+            RtlCopyUnicodeString( &env_value, &tmp );
         }
-        else
+        /* PATH is magic */
+        if (env_name.Length == sizeof(pathW) &&
+            !memicmpW( env_name.Buffer, pathW, sizeof(pathW)/sizeof(WCHAR) ) &&
+            !RtlQueryEnvironmentVariable_U( NULL, &env_name, &tmp ))
         {
-            RtlSetEnvironmentVariable( NULL, &env_name, &env_value );
+            RtlAppendUnicodeToString( &tmp, sep );
+            if (RtlAppendUnicodeStringToString( &tmp, &env_value )) continue;
+            RtlCopyUnicodeString( &env_value, &tmp );
         }
+        RtlSetEnvironmentVariable( NULL, &env_name, &env_value );
     }
 }
 




More information about the wine-cvs mailing list