// Environment block == null-terminated block of null-terminated strings of the form: name=value\0 wchar_t * XWinProcessLauncher::_CreateEnvironmentVariablesBlock(const EnvVarNamesAndValuesMap &inVarToUse) { wchar_t * initialEnvStrings = NULL; VMemoryBuffer<> allStrings; wchar_t * theEnvVarBlock = NULL; // Initial environment variables initialEnvStrings = ::GetEnvironmentStringsW(); if(initialEnvStrings != NULL) { wchar_t *currentStr = initialEnvStrings; size_t fullStrSize; while (*currentStr) { fullStrSize = ::wcslen(currentStr) + 1; allStrings.PutData(allStrings.GetDataSize(), currentStr, fullStrSize * sizeof(wchar_t)); currentStr += fullStrSize; } } // Prepare our envir. variables if(!inVarToUse.empty()) { XBOX::VString oneEnvVarAndValue; EnvVarNamesAndValuesMap::const_iterator envVarIterator; // Calculate final buffer size (concatenate name=value and add the 0 terminattion) for (envVarIterator = inVarToUse.begin(); envVarIterator != inVarToUse.end(); envVarIterator++) { oneEnvVarAndValue = envVarIterator->first; if(!oneEnvVarAndValue.IsEmpty()) { oneEnvVarAndValue += "="; oneEnvVarAndValue += envVarIterator->second; const wchar_t * varValueCStr = oneEnvVarAndValue.GetCPointer(); // Null terminated UniCode string. if(testAssert(varValueCStr != NULL)) { allStrings.PutData(allStrings.GetDataSize(), varValueCStr, (oneEnvVarAndValue.GetLength() + 1) * sizeof(wchar_t)); } } } } //if(!inVarToUse.empty()) if(allStrings.GetDataSize() > 0) { wchar_t theZero = 0; allStrings.PutData(allStrings.GetDataSize(), &theZero, sizeof(wchar_t)); theEnvVarBlock = new wchar_t[allStrings.GetDataSize()]; if(testAssert(theEnvVarBlock)) allStrings.GetData(0, theEnvVarBlock, allStrings.GetDataSize()); } if(initialEnvStrings != NULL) ::FreeEnvironmentStringsW(initialEnvStrings); return theEnvVarBlock; }
// Environment block == null-terminated block of null-terminated strings of the form: name=value\0 char * XWinProcessLauncher::_CreateEnvironmentVariablesBlock(const EnvVarNamesAndValuesMap &inVarToUse) { char *initialEnvStrings = NULL; VMemoryBuffer<> allStrings; char * theEnvVarBlock = NULL; // Initial environment variables initialEnvStrings = ::GetEnvironmentStrings(); if(initialEnvStrings != NULL) { char *currentStr = initialEnvStrings; size_t fullStrSize; while(*currentStr) { fullStrSize = strlen(currentStr) + 1; allStrings.PutData(allStrings.GetDataSize(), currentStr, fullStrSize); currentStr += fullStrSize; } } // Prepare our envir. variables if(!inVarToUse.empty()) { XBOX::VString oneEnvVarAndValue; // Calculate final buffer size (concatenate name=value and add the 0 terminattion) EnvVarNamesAndValuesMap::const_iterator envVarIterator = inVarToUse.begin(); while(envVarIterator != inVarToUse.end()) { oneEnvVarAndValue = envVarIterator->first; if(!oneEnvVarAndValue.IsEmpty()) { oneEnvVarAndValue += "="; oneEnvVarAndValue += envVarIterator->second; char *varValueCStr = _CreateCString(oneEnvVarAndValue); if(testAssert(varValueCStr != NULL)) { allStrings.PutData(allStrings.GetDataSize(), varValueCStr, strlen(varValueCStr) + 1); delete [] varValueCStr; } } ++envVarIterator; } } //if(!inVarToUse.empty()) if(allStrings.GetDataSize() > 0) { char theZero = 0; allStrings.PutData(allStrings.GetDataSize(), &theZero, 1); theEnvVarBlock = new char[allStrings.GetDataSize()]; if(testAssert(theEnvVarBlock)) allStrings.GetData(0, theEnvVarBlock, allStrings.GetDataSize()); } if(initialEnvStrings != NULL) ::FreeEnvironmentStrings(initialEnvStrings); return theEnvVarBlock; }