1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added function: SystemStats::getEnvironmentVariable()

This commit is contained in:
jules 2012-07-18 16:17:36 +01:00
parent 18ce7d1a5b
commit 2d9312ca3e
3 changed files with 30 additions and 0 deletions

View file

@ -525,6 +525,17 @@ Result FileOutputStream::truncate()
return getResultForReturnValue (ftruncate (getFD (fileHandle), (off_t) currentPosition));
}
//==============================================================================
String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
{
const char* s = ::getenv (name.toUTF8());
if (s != nullptr)
return String::fromUTF8 (s);
return defaultValue;
}
//==============================================================================
MemoryMappedFile::MemoryMappedFile (const File& file, MemoryMappedFile::AccessMode mode)
: address (nullptr),

View file

@ -198,6 +198,20 @@ int SystemStats::getMemorySizeInMegabytes()
return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
}
//==============================================================================
String SystemStats::getEnvironmentVariable (const String& name, const String& defaultValue)
{
DWORD len = GetEnvironmentVariableW (name.toWideCharPointer(), nullptr, 0);
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return String (defaultValue);
HeapBlock<WCHAR> buffer (len);
len = GetEnvironmentVariableW (name.toWideCharPointer(), buffer, len);
return String (CharPointer_wchar_t (buffer),
CharPointer_wchar_t (buffer + len));
}
//==============================================================================
uint32 juce_millisecondsSinceStartup() noexcept
{

View file

@ -94,6 +94,11 @@ public:
static int getOSXMinorVersionNumber();
#endif
/** Returns an environment variable.
If the named value isn't set, this will return the defaultValue string instead.
*/
static String getEnvironmentVariable (const String& name, const String& defaultValue);
//==============================================================================
/** Returns the current user's name, if available.
@see getFullUserName()