MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / GetEnvVar

Function GetEnvVar

Source/ThirdParty/tracy/common/TracySystem.cpp:316–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 9

InitCallstackFunction · 0.85
GetSamplingFrequencyFunction · 0.85
SysTraceStartFunction · 0.85
ProfilerMethod · 0.85
SpawnWorkerThreadsMethod · 0.85
ListenMethod · 0.85

Calls 1

memcpyFunction · 0.85

Tested by

no test coverage detected