summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Process.inc
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-09-10 19:45:51 +0000
committerRui Ueyama <ruiu@google.com>2013-09-10 19:45:51 +0000
commit471d0c57e789b57302329761f678e48dffc8d41d (patch)
tree0045e4ae4f9bdb12e6c3844a8123761836955974 /llvm/lib/Support/Unix/Process.inc
parent934f6f39f49febece76d5532346ba5bb297ad7ea (diff)
downloadbcm5719-llvm-471d0c57e789b57302329761f678e48dffc8d41d.tar.gz
bcm5719-llvm-471d0c57e789b57302329761f678e48dffc8d41d.zip
Add getenv() wrapper that works on multibyte environment variable.
On Windows, character encoding of multibyte environment variable varies depending on settings. The only reliable way to handle it I think is to use GetEnvironmentVariableW(). GetEnvironmentVariableW() works on wchar_t string, which is on Windows UTF16 string. That's not ideal because we use UTF-8 as the internal encoding in LLVM. This patch defines a wrapper function which takes and returns UTF-8 string for GetEnvironmentVariableW(). The wrapper function does not do any conversion and just forwards the argument to getenv() on Unix. Differential Revision: http://llvm-reviews.chandlerc.com/D1612 llvm-svn: 190423
Diffstat (limited to 'llvm/lib/Support/Unix/Process.inc')
-rw-r--r--llvm/lib/Support/Unix/Process.inc9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 47d0a3c794d..7d8f6250136 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -13,6 +13,7 @@
#include "Unix.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/TimeValue.h"
@@ -181,6 +182,14 @@ void Process::PreventCoreFiles() {
#endif
}
+Optional<std::string> Process::GetEnv(StringRef Name) {
+ std::string NameStr = Name.str();
+ const char *Val = ::getenv(NameStr.c_str());
+ if (!Val)
+ return None;
+ return std::string(Val);
+}
+
bool Process::StandardInIsUserInput() {
return FileDescriptorIsDisplayed(STDIN_FILENO);
}
OpenPOWER on IntegriCloud