aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/Unix/Program.inc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/Unix/Program.inc')
-rw-r--r--lib/Support/Unix/Program.inc26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc
index 0670ad3..baf2767 100644
--- a/lib/Support/Unix/Program.inc
+++ b/lib/Support/Unix/Program.inc
@@ -42,7 +42,18 @@
#define _RESTRICT_KYWD
#endif
#include <spawn.h>
-#if !defined(__APPLE__)
+
+#if defined(__APPLE__)
+#include <TargetConditionals.h>
+#endif
+
+#if defined(__APPLE__) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
+#define USE_NSGETENVIRON 1
+#else
+#define USE_NSGETENVIRON 0
+#endif
+
+#if !USE_NSGETENVIRON
extern char **environ;
#else
#include <crt_externs.h> // _NSGetEnviron
@@ -63,11 +74,12 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name,
if (Name.find('/') != StringRef::npos)
return std::string(Name);
- if (Paths.empty()) {
- SmallVector<StringRef, 16> SearchPaths;
- SplitString(std::getenv("PATH"), SearchPaths, ":");
- return findProgramByName(Name, SearchPaths);
- }
+ SmallVector<StringRef, 16> EnvironmentPaths;
+ if (Paths.empty())
+ if (const char *PathEnv = std::getenv("PATH")) {
+ SplitString(PathEnv, EnvironmentPaths, ":");
+ Paths = EnvironmentPaths;
+ }
for (auto Path : Paths) {
if (Path.empty())
@@ -216,7 +228,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
}
if (!envp)
-#if !defined(__APPLE__)
+#if !USE_NSGETENVIRON
envp = const_cast<const char **>(environ);
#else
// environ is missing in dylibs.