forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnviron.cpp
54 lines (46 loc) · 1.13 KB
/
Environ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#include <MaterialXFormat/Environ.h>
#include <MaterialXCore/Util.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
namespace MaterialX
{
string getEnviron(const string& name)
{
#if defined(_WIN32)
if (uint32_t size = GetEnvironmentVariable(name.c_str(), nullptr, 0))
{
vector<char> buffer(size);
GetEnvironmentVariable(name.c_str(), buffer.data(), size);
return string(buffer.data());
}
#else
if (const char* const result = getenv(name.c_str()))
{
return string(result);
}
#endif
return EMPTY_STRING;
}
bool setEnviron(const string& name, const string& value)
{
#if defined(_WIN32)
return SetEnvironmentVariable(name.c_str(), value.c_str()) != 0;
#else
return setenv(name.c_str(), value.c_str(), true);
#endif
}
bool removeEnviron(const string& name)
{
#if defined(_WIN32)
return SetEnvironmentVariable(name.c_str(), nullptr) != 0;
#else
return unsetenv(name.c_str()) == 0;
#endif
}
} // namespace MaterialX