Fix windows environment variable fetching to use win32 functions

This commit is contained in:
baldurk
2017-09-04 11:01:40 +01:00
parent ac77eeb98e
commit 8e40cabd57
+9 -2
View File
@@ -157,9 +157,16 @@ void Process::ApplyEnvironmentModification()
const char *Process::GetEnvVariable(const char *name)
{
DWORD ret = GetEnvironmentVariableA(name, NULL, 0);
if(ret == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return NULL;
static char buf[1024] = {};
size_t reqSize = 1024;
getenv_s(&reqSize, buf, name);
if(ret >= 1024)
RDCERR("Static buffer insufficiently sized");
RDCEraseEl(buf);
GetEnvironmentVariableA(name, buf, RDCMIN((DWORD)1023U, ret));
return buf;
}