[PATCH 2/5] userenv: Use wide character string literals.

Zebediah Figura z.figura12 at gmail.com
Tue Nov 5 21:48:56 CST 2019


Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
 dlls/userenv/userenv_main.c | 114 ++++++++++++------------------------
 1 file changed, 38 insertions(+), 76 deletions(-)

diff --git a/dlls/userenv/userenv_main.c b/dlls/userenv/userenv_main.c
index 005166e5f4..9317c82735 100644
--- a/dlls/userenv/userenv_main.c
+++ b/dlls/userenv/userenv_main.c
@@ -95,10 +95,6 @@ static BOOL get_reg_value(WCHAR *env, HKEY hkey, const WCHAR *name, WCHAR *val,
 
 static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_path)
 {
-    static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
-    static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
-    static const WCHAR PATHW[] = {'P','A','T','H',0};
-
     UNICODE_STRING us_name, us_value;
     WCHAR name[1024], value[1024];
     DWORD ret, index, size;
@@ -110,13 +106,13 @@ static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_
         if (ret != ERROR_SUCCESS)
             break;
 
-        if (!wcsicmp(name, SystemRootW)) continue;
-        if (!wcsicmp(name, SystemDriveW)) continue;
+        if (!wcsicmp(name, L"SystemRoot")) continue;
+        if (!wcsicmp(name, L"SystemDrive")) continue;
 
         RtlInitUnicodeString(&us_name, name);
         us_value.Buffer = value;
         us_value.MaximumLength = sizeof(value);
-        if (!wcsnicmp(name, PATHW, ARRAY_SIZE(PATHW)) &&
+        if (!wcsicmp(name, L"PATH") &&
                 !RtlQueryEnvironmentVariable_U(*env, &us_name, &us_value))
         {
             if (!set_path)
@@ -146,19 +142,6 @@ static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_
 
 static void set_wow64_environment(WCHAR **env)
 {
-    static const WCHAR versionW[] = {'S','o','f','t','w','a','r','e','\\',
-        'M','i','c','r','o','s','o','f','t','\\',
-        'W','i','n','d','o','w','s','\\',
-        'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
-    static const WCHAR progdirW[]   = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
-    static const WCHAR progdir86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
-    static const WCHAR progfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0};
-    static const WCHAR progw6432W[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0};
-    static const WCHAR commondirW[]   = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
-    static const WCHAR commondir86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
-    static const WCHAR commonfilesW[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0};
-    static const WCHAR commonw6432W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0};
-
     UNICODE_STRING nameW, valueW;
     WCHAR buf[64];
     HKEY hkey;
@@ -167,54 +150,54 @@ static void set_wow64_environment(WCHAR **env)
 
     IsWow64Process( GetCurrentProcess(), &is_wow64 );
 
-    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, versionW, 0,
-                KEY_READ|KEY_WOW64_64KEY, &hkey))
+    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion",
+            0, KEY_READ|KEY_WOW64_64KEY, &hkey))
         return;
 
     /* set the ProgramFiles variables */
 
-    if (get_reg_value(*env, hkey, progdirW, buf, sizeof(buf)))
+    if (get_reg_value(*env, hkey, L"ProgramFilesDir", buf, sizeof(buf)))
     {
         if (is_win64 || is_wow64)
         {
-            RtlInitUnicodeString(&nameW, progw6432W);
+            RtlInitUnicodeString(&nameW, L"ProgramW6432");
             RtlInitUnicodeString(&valueW, buf);
             RtlSetEnvironmentVariable(env, &nameW, &valueW);
         }
         if (is_win64 || !is_wow64)
         {
-            RtlInitUnicodeString(&nameW, progfilesW);
+            RtlInitUnicodeString(&nameW, L"ProgramFiles");
             RtlInitUnicodeString(&valueW, buf);
             RtlSetEnvironmentVariable(env, &nameW, &valueW);
         }
     }
-    if (is_wow64 && get_reg_value(*env, hkey, progdir86W, buf, sizeof(buf)))
+    if (is_wow64 && get_reg_value(*env, hkey, L"ProgramFilesDir (x86)", buf, sizeof(buf)))
     {
-        RtlInitUnicodeString(&nameW, progfilesW);
+        RtlInitUnicodeString(&nameW, L"ProgramFiles");
         RtlInitUnicodeString(&valueW, buf);
         RtlSetEnvironmentVariable(env, &nameW, &valueW);
     }
 
     /* set the CommonProgramFiles variables */
 
-    if (get_reg_value(*env, hkey, commondirW, buf, sizeof(buf)))
+    if (get_reg_value(*env, hkey, L"CommonFilesDir", buf, sizeof(buf)))
     {
         if (is_win64 || is_wow64)
         {
-            RtlInitUnicodeString(&nameW, commonw6432W);
+            RtlInitUnicodeString(&nameW, L"CommonProgramW6432");
             RtlInitUnicodeString(&valueW, buf);
             RtlSetEnvironmentVariable(env, &nameW, &valueW);
         }
         if (is_win64 || !is_wow64)
         {
-            RtlInitUnicodeString(&nameW, commonfilesW);
+            RtlInitUnicodeString(&nameW, L"CommonProgramFiles");
             RtlInitUnicodeString(&valueW, buf);
             RtlSetEnvironmentVariable(env, &nameW, &valueW);
         }
     }
-    if (is_wow64 && get_reg_value(*env, hkey, commondir86W, buf, sizeof(buf)))
+    if (is_wow64 && get_reg_value(*env, hkey, L"CommonFilesDir (x86)", buf, sizeof(buf)))
     {
-        RtlInitUnicodeString(&nameW, commonfilesW);
+        RtlInitUnicodeString(&nameW, L"CommonProgramFiles");
         RtlInitUnicodeString(&valueW, buf);
         RtlSetEnvironmentVariable(env, &nameW, &valueW);
     }
@@ -225,28 +208,8 @@ static void set_wow64_environment(WCHAR **env)
 BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
                      HANDLE hToken, BOOL bInherit )
 {
-    static const WCHAR env_keyW[] = {'S','y','s','t','e','m','\\',
-        'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-        'C','o','n','t','r','o','l','\\',
-        'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\\',
-        'E','n','v','i','r','o','n','m','e','n','t',0};
-    static const WCHAR profile_keyW[] = {'S','o','f','t','w','a','r','e','\\',
-        'M','i','c','r','o','s','o','f','t','\\',
-        'W','i','n','d','o','w','s',' ','N','T','\\',
-        'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
-        'P','r','o','f','i','l','e','L','i','s','t',0};
-    static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
-    static const WCHAR volatile_envW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0};
-    static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
-
-    static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
-    static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0};
-    static const WCHAR PublicW[] = {'P','u','b','l','i','c',0};
-    static const WCHAR ALLUSERSPROFILEW[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0};
-    static const WCHAR USERNAMEW[] = {'U','S','E','R','N','A','M','E',0};
-    static const WCHAR USERPROFILEW[] = {'U','S','E','R','P','R','O','F','I','L','E',0};
-    static const WCHAR DefaultW[] = {'D','e','f','a','u','l','t',0};
-    static const WCHAR COMPUTERNAMEW[] = {'C','O','M','P','U','T','E','R','N','A','M','E',0};
+    static const WCHAR env_keyW[] = L"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
+    static const WCHAR profile_keyW[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
 
     WCHAR *env, buf[UNICODE_STRING_MAX_CHARS], profiles_dir[MAX_PATH];
     UNICODE_STRING us_name, us_val;
@@ -267,41 +230,41 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
         return FALSE;
     }
 
-    if (!GetEnvironmentVariableW(SystemRootW, buf, UNICODE_STRING_MAX_CHARS))
+    if (!GetEnvironmentVariableW(L"SystemRoot", buf, UNICODE_STRING_MAX_CHARS))
     {
-        if (!get_reg_value(env, hkey, SystemRootW, buf, UNICODE_STRING_MAX_CHARS))
+        if (!get_reg_value(env, hkey, L"SystemRoot", buf, UNICODE_STRING_MAX_CHARS))
         {
             buf[0] = 0;
             WARN("SystemRoot variable not set\n");
         }
     }
-    RtlInitUnicodeString(&us_name, SystemRootW);
+    RtlInitUnicodeString(&us_name, L"SystemRoot");
     RtlInitUnicodeString(&us_val, buf);
     RtlSetEnvironmentVariable(&env, &us_name, &us_val);
 
-    if (!GetEnvironmentVariableW(SystemDriveW, buf, UNICODE_STRING_MAX_CHARS))
+    if (!GetEnvironmentVariableW(L"SystemDrive", buf, UNICODE_STRING_MAX_CHARS))
     {
-        if (!get_reg_value(env, hkey, SystemDriveW, buf, UNICODE_STRING_MAX_CHARS))
+        if (!get_reg_value(env, hkey, L"SystemDrive", buf, UNICODE_STRING_MAX_CHARS))
         {
             buf[0] = 0;
             WARN("SystemDrive variable not set\n");
         }
     }
-    RtlInitUnicodeString(&us_name, SystemDriveW);
+    RtlInitUnicodeString(&us_name, L"SystemDrive");
     RtlInitUnicodeString(&us_val, buf);
     RtlSetEnvironmentVariable(&env, &us_name, &us_val);
 
     set_registry_variables(&env, hkey, REG_SZ, !bInherit);
     set_registry_variables(&env, hkey, REG_EXPAND_SZ, !bInherit);
 
-    if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
+    if (RegOpenKeyExW(hkey, L"Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
     {
         set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
         set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
         RegCloseKey(hsubkey);
     }
 
-    if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
+    if (RegOpenKeyExW(hkey, L"Volatile Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
     {
         set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
         set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
@@ -311,7 +274,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
 
     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, profile_keyW, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
     {
-        if (get_reg_value(env, hkey, ProfilesDirectoryW, profiles_dir, MAX_PATH-sizeof(WCHAR)))
+        if (get_reg_value(env, hkey, L"ProfilesDirectory", profiles_dir, MAX_PATH - sizeof(WCHAR)))
         {
             len = lstrlenW(profiles_dir);
             if (profiles_dir[len-1] != '\\')
@@ -320,9 +283,9 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
                 profiles_dir[len] = '\0';
             }
 
-            if (get_reg_value(env, hkey, PublicW, buf, UNICODE_STRING_MAX_CHARS))
+            if (get_reg_value(env, hkey, L"Public", buf, UNICODE_STRING_MAX_CHARS))
             {
-                RtlInitUnicodeString(&us_name, ALLUSERSPROFILEW);
+                RtlInitUnicodeString(&us_name, L"ALLUSERSPROFILE");
                 RtlInitUnicodeString(&us_val, buf);
                 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
             }
@@ -338,7 +301,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
     len = ARRAY_SIZE(buf);
     if (GetComputerNameW(buf, &len))
     {
-        RtlInitUnicodeString(&us_name, COMPUTERNAMEW);
+        RtlInitUnicodeString(&us_name, L"COMPUTERNAME");
         RtlInitUnicodeString(&us_val, buf);
         RtlSetEnvironmentVariable(&env, &us_name, &us_val);
     }
@@ -350,18 +313,17 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
         if (profiles_dir[0])
         {
             len = lstrlenW(profiles_dir);
-            if (len*sizeof(WCHAR)+sizeof(DefaultW) < sizeof(buf))
+            if (len * sizeof(WCHAR) + sizeof(L"Default") < sizeof(buf))
             {
-                memcpy(buf, profiles_dir, len*sizeof(WCHAR));
-                memcpy(buf+len, DefaultW, sizeof(DefaultW));
-                RtlInitUnicodeString(&us_name, USERPROFILEW);
+                wcscpy(buf, profiles_dir);
+                wcscat(buf, L"Default");
+                RtlInitUnicodeString(&us_name, L"USERPROFILE");
                 RtlInitUnicodeString(&us_val, buf);
                 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
             }
         }
 
-        buf[0] = '.';
-        memcpy(buf+1, DefaultW, sizeof(DefaultW));
+        wcscpy(buf, L".Default");
     }
     else
     {
@@ -388,13 +350,13 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
         if (LookupAccountSidW(NULL, token_user->User.Sid,
                     buf+len, &size, NULL, &tmp, &use))
         {
-            RtlInitUnicodeString(&us_name, USERNAMEW);
+            RtlInitUnicodeString(&us_name, L"USERNAME");
             RtlInitUnicodeString(&us_val, buf+len);
             RtlSetEnvironmentVariable(&env, &us_name, &us_val);
 
             if (len)
             {
-                RtlInitUnicodeString(&us_name, USERPROFILEW);
+                RtlInitUnicodeString(&us_name, L"USERPROFILE");
                 RtlInitUnicodeString(&us_val, buf);
                 RtlSetEnvironmentVariable(&env, &us_name, &us_val);
             }
@@ -407,14 +369,14 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
 
     if (RegOpenKeyExW(HKEY_USERS, buf, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
     {
-        if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
+        if (RegOpenKeyExW(hkey, L"Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
         {
             set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
             set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
             RegCloseKey(hsubkey);
         }
 
-        if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
+        if (RegOpenKeyExW(hkey, L"Volatile Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS)
         {
             set_registry_variables(&env, hsubkey, REG_SZ, !bInherit);
             set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
-- 
2.23.0




More information about the wine-devel mailing list