Changeset 96587 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Sep 3, 2022 2:37:15 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/win/env-win.cpp
r96407 r96587 72 72 int rtEnvSetUtf8Worker(const char *pchVar, size_t cchVar, const char *pszValue); 73 73 74 75 #if defined(RT_ARCH_X86) && defined(RT_OS_WINDOWS) 76 /** 77 * This is a workaround for NT 3.x not setting the last error. 78 */ 79 static DWORD rtEnvNt31CheckEmpty(PCRTUTF16 pwszVar) 80 { 81 /* Check the version first: */ 82 DWORD dwVersion = GetVersion(); 83 if (RT_BYTE1(dwVersion) != 3) 84 return 0; 85 86 /* When called with an empty buffer, we should get 1 if empty value 87 and 0 if not found: */ 88 DWORD cwcNeeded = GetEnvironmentVariableW(pwszVar, NULL, 0); 89 return cwcNeeded == 0 ? ERROR_ENVVAR_NOT_FOUND : NO_ERROR; 90 } 91 #endif 74 92 75 93 … … 173 191 for (unsigned iTry = 0;; iTry++) 174 192 { 175 /* This API is weird, it didn't always set ERROR_BUFFER_OVERFLOW .193 /* This API is weird, it didn't always set ERROR_BUFFER_OVERFLOW nor ERROR_ENVVAR_NOT_FOUND. 176 194 Note! Assume that the CRT transparently updates the process 177 195 environment and that we don't need to use _wgetenv_s here. */ 178 196 SetLastError(NO_ERROR); 179 197 DWORD const cwcValueRet = GetEnvironmentVariableW(pwszVar, pwszValue, cwcValueBuf); 180 DWORD constdwErr = GetLastError();198 DWORD dwErr = GetLastError(); 181 199 182 200 if (cwcValueRet < cwcValueBuf) 183 201 { 202 #ifdef RT_ARCH_X86 203 if (cwcValueRet == 0 && dwErr == NO_ERROR) 204 dwErr = rtEnvNt31CheckEmpty(pwszVar); 205 #endif 184 206 if (cwcValueRet > 0 || dwErr == NO_ERROR) /* In case of empty values we have to see if last error was set or not. */ 185 207 { … … 241 263 for (unsigned iTry = 0;; iTry++) 242 264 { 243 /* This API is weird, it didn't always set ERROR_BUFFER_OVERFLOW .265 /* This API is weird, it didn't always set ERROR_BUFFER_OVERFLOW nor ERROR_ENVVAR_NOT_FOUND. 244 266 Note! Assume that the CRT transparently updates the process 245 267 environment and that we don't need to use _wgetenv_s here. */ 246 268 SetLastError(NO_ERROR); 247 269 DWORD const cwcValueRet = GetEnvironmentVariableW(pwszVar, pwszValue, cwcValueBuf); 248 DWORD constdwErr = GetLastError();270 DWORD dwErr = GetLastError(); 249 271 250 272 if (cwcValueRet < cwcValueBuf) 251 273 { 274 #ifdef RT_ARCH_X86 275 if (cwcValueRet == 0 && dwErr == NO_ERROR) 276 dwErr = rtEnvNt31CheckEmpty(pwszVar); 277 #endif 252 278 if (cwcValueRet > 0 || dwErr == NO_ERROR) /* In case of empty values we have to see if last error was set or not. */ 253 279 {
Note:
See TracChangeset
for help on using the changeset viewer.