| 303 | } |
| 304 | |
| 305 | TRACY_API const char* GetEnvVar( const char* name ) |
| 306 | { |
| 307 | #if defined _WIN32 |
| 308 | // unfortunately getenv() on Windows is just fundamentally broken. It caches the entire |
| 309 | // environment block once on startup, then never refreshes it again. If any environment |
| 310 | // strings are added or modified after startup of the CRT, those changes will not be |
| 311 | // seen by getenv(). This removes the possibility of an app using this SDK from |
| 312 | // programmatically setting any of the behaviour controlling envvars here. |
| 313 | // |
| 314 | // To work around this, we'll instead go directly to the Win32 environment strings APIs |
| 315 | // to get the current value. |
| 316 | static char buffer[1024]; |
| 317 | DWORD const kBufferSize = DWORD(sizeof(buffer) / sizeof(buffer[0])); |
| 318 | DWORD count = GetEnvironmentVariableA(name, buffer, kBufferSize); |
| 319 | |
| 320 | if( count == 0 ) |
| 321 | return nullptr; |
| 322 | |
| 323 | if( count >= kBufferSize ) |
| 324 | { |
| 325 | char* buf = reinterpret_cast<char*>(_alloca(count + 1)); |
| 326 | count = GetEnvironmentVariableA(name, buf, count + 1); |
| 327 | memcpy(buffer, buf, kBufferSize); |
| 328 | buffer[kBufferSize - 1] = 0; |
| 329 | } |
| 330 | |
| 331 | return buffer; |
| 332 | #else |
| 333 | return getenv(name); |
| 334 | #endif |
| 335 | } |
| 336 | |
| 337 | } |
| 338 |
no outgoing calls
no test coverage detected