[Windows] Use the same API for all OS_Windows::*_environment functions.

(cherry picked from commit 319bfa9965)
This commit is contained in:
bruvzg 2024-09-03 16:02:35 +03:00 committed by Rémi Verschelde
parent e09cada53f
commit b1c1c40250
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -1500,16 +1500,7 @@ String OS_Windows::get_executable_path() const {
}
bool OS_Windows::has_environment(const String &p_var) const {
#ifdef MINGW_ENABLED
return _wgetenv((LPCWSTR)(p_var.utf16().get_data())) != nullptr;
#else
WCHAR *env;
size_t len;
_wdupenv_s(&env, &len, (LPCWSTR)(p_var.utf16().get_data()));
const bool has_env = env != nullptr;
free(env);
return has_env;
#endif
return GetEnvironmentVariableW((LPCWSTR)(p_var.utf16().get_data()), nullptr, 0) > 0;
}
String OS_Windows::get_environment(const String &p_var) const {