MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / Getenv

Function Getenv

src/OpenColorIO/Platform.cpp:48–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46{
47
48bool Getenv(const char * name, std::string & value)
49{
50 if (!name || !*name)
51 {
52 return false;
53 }
54
55#if defined(_WIN32)
56 // Define working strings, converting to UTF-16 if necessary
57#ifdef UNICODE
58 std::wstring name_str = Utf8ToUtf16(name);
59 std::wstring value_str;
60#else
61 std::string name_str = name;
62 std::string value_str;
63#endif
64
65 if(uint32_t size = GetEnvironmentVariable(name_str.c_str(), nullptr, 0))
66 {
67 value_str.resize(size);
68
69 GetEnvironmentVariable(name_str.c_str(), &value_str[0], size);
70
71 // GetEnvironmentVariable is designed for raw pointer strings and therefore requires that
72 // the destination buffer be long enough to place a null terminator at the end of it. Since
73 // we're using std::wstrings here, the null terminator is unnecessary (and causes false
74 // negatives in unit tests since the extra character makes it "non-equal" to normally
75 // defined std::wstrings). Therefore, we pop the last character off (the null terminator)
76 // to ensure that the string conforms to expectations.
77 value_str.pop_back();
78
79 // Return value, converting to UTF-8 if necessary
80#ifdef UNICODE
81 value = Utf16ToUtf8(value_str);
82#else
83 value = value_str;
84#endif
85 return true;
86 }
87 else
88 {
89 value.clear();
90 return false;
91 }
92#else
93 const char * val = ::getenv(name);
94 value = (val && *val) ? val : "";
95 return val; // Returns true if the env. variable exists but empty.
96#endif
97}
98
99void Setenv(const char * name, const std::string & value)
100{

Callers 8

GetEnvVariableFunction · 0.85
isEnvPresentFunction · 0.85
ImplMethod · 0.85
instantiateDisplayMethod · 0.85
CreateFromEnvMethod · 0.85
InitLoggingFunction · 0.85
CreateMethod · 0.85
OCIO_ADD_TESTFunction · 0.85

Calls 5

Utf8ToUtf16Function · 0.85
Utf16ToUtf8Function · 0.85
pop_backMethod · 0.80
resizeMethod · 0.45
clearMethod · 0.45

Tested by 1

OCIO_ADD_TESTFunction · 0.68