Skip to content

Commit 28fd6b4

Browse files
authored
Use getenv_s
1 parent a256714 commit 28fd6b4

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

lib/Interpreter/DynamicLibraryManager.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ namespace Cpp {
5252
// Behaviour is to not add paths that don't exist...In an interpreted env
5353
// does this make sense? Path could pop into existance at any time.
5454
for (const char* Var : kSysLibraryEnv) {
55-
#ifdef _WIN32
5655
char* Env = nullptr;
5756
size_t sz = 0;
58-
if (_dupenv_s(&Env, &sz, Var)) {
59-
#else
60-
if (const char* Env = ::getenv(Var)) {
61-
#endif
57+
if (getenv_s(&sz,&Env, &sz, Var)) {
6258
SmallVector<StringRef, 10> CurPaths;
6359
SplitPaths(Env, CurPaths, utils::kPruneNonExistant, Cpp::utils::platform::kEnvDelim);
6460
for (const auto& Path : CurPaths)

lib/Interpreter/Paths.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,14 @@ bool ExpandEnvVars(std::string& Str, bool Path) {
168168

169169
std::string EnvVar = Str.substr(DPos + 1, Length -1); //"HOME"
170170
std::string FullPath;
171-
#ifdef _WIN32
172171
char* Tok = nullptr;
173172
size_t sz = 0;
174-
if (_dupenv_s(&Tok, &sz, EnvVar.c_str()))
175-
#else
176-
if (const char* Tok = getenv(EnvVar.c_str()))
177-
#endif
173+
if (getenv_s(&sz,&Tok, &sz, EnvVar.c_str())) {
178174
FullPath = Tok;
179175

180-
Str.replace(DPos, Length, FullPath);
181-
DPos = Str.find("$", DPos + 1); //search for next env variable
182-
}
176+
Str.replace(DPos, Length, FullPath);
177+
DPos = Str.find("$", DPos + 1); //search for next env variable
178+
}
183179
if (!Path)
184180
return true;
185181
return llvm::sys::fs::exists(Str.c_str());

0 commit comments

Comments
 (0)