[llvm] r276572 - [CommandLine] Use Process::GetEnv instead of _wgetenv
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 24 10:20:01 PDT 2016
Author: majnemer
Date: Sun Jul 24 12:19:59 2016
New Revision: 276572
URL: http://llvm.org/viewvc/llvm-project?rev=276572&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Support/CommandLine.cpp
Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=276572&r1=276571&r2=276572&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Sun Jul 24 12:19:59 2016
@@ -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 <cstdlib>
@@ -951,28 +953,9 @@ void cl::ParseEnvironmentOptions(const c
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<std::string> 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 c
// 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<int>(newArgv.size());
ParseCommandLineOptions(newArgc, &newArgv[0], Overview);
}
More information about the llvm-commits
mailing list