From afb38afd5f2f89c746cb6293a493958f90560b9f Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 24 Jul 2016 17:19:59 +0000 Subject: [CommandLine] Use Process::GetEnv instead of _wgetenv Process::GetEnv does the right thing across our platforms. CommandLine.cpp had, more or less, the same logic. Let's remove the duplication. No functional change is intended. llvm-svn: 276572 --- llvm/lib/Support/CommandLine.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'llvm/lib/Support/CommandLine.cpp') diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index 3b1b3eb7e55..1b468a0aa9a 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -20,6 +20,7 @@ #include "llvm-c/Support.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" @@ -33,6 +34,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" #include @@ -951,28 +953,9 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, assert(envVar && "Environment variable name missing"); // Get the environment variable they want us to parse options out of. -#ifdef _WIN32 - std::wstring wenvVar; - if (!llvm::ConvertUTF8toWide(envVar, wenvVar)) { - assert(false && - "Unicode conversion of environment variable name failed"); - return; - } - const wchar_t *wenvValue = _wgetenv(wenvVar.c_str()); - if (!wenvValue) - return; - std::string envValueBuffer; - if (!llvm::convertWideToUTF8(wenvValue, envValueBuffer)) { - assert(false && - "Unicode conversion of environment variable value failed"); - return; - } - const char *envValue = envValueBuffer.c_str(); -#else - const char *envValue = getenv(envVar); + llvm::Optional envValue = sys::Process::GetEnv(envVar); if (!envValue) return; -#endif // Get program's "name", which we wouldn't know without the caller // telling us. @@ -983,7 +966,7 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar, // Parse the value of the environment variable into a "command line" // and hand it off to ParseCommandLineOptions(). - TokenizeGNUCommandLine(envValue, Saver, newArgv); + TokenizeGNUCommandLine(*envValue, Saver, newArgv); int newArgc = static_cast(newArgv.size()); ParseCommandLineOptions(newArgc, &newArgv[0], Overview); } -- cgit v1.2.3