aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-03-13 05:22:05 +0000
committerChris Lattner <sabre@nondot.org>2008-03-13 05:22:05 +0000
commit3bdfa04cbe42106d2dc55d0dd980ba9e52a3bd84 (patch)
tree84c422d293b5696819f38a885463f3559a1fe574
parenta17fa28ac2a2d1fca5ca208f1e9fb8e4f3be3d73 (diff)
downloadexternal_llvm-3bdfa04cbe42106d2dc55d0dd980ba9e52a3bd84.zip
external_llvm-3bdfa04cbe42106d2dc55d0dd980ba9e52a3bd84.tar.gz
external_llvm-3bdfa04cbe42106d2dc55d0dd980ba9e52a3bd84.tar.bz2
Fix Path::GetMainExecutable on cygwin, patch by Sam Bishop.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48328 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/System/Unix/Path.inc11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 8e76b54..e112132 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -251,8 +251,17 @@ Path::GetCurrentDirectory() {
/// GetMainExecutable - Return the path to the main executable, given the
/// value of argv[0] from program startup.
Path Path::GetMainExecutable(const char *argv0, void *MainAddr) {
+#if defined(__CYGWIN__)
+ char exe_link[64];
+ snprintf(exe_link, sizeof(exe_link), "/proc/%d/exe", getpid());
+ char exe_path[MAXPATHLEN];
+ ssize_t len = readlink(exe_link, exe_path, sizeof(exe_path));
+ if (len > 0 && len < MAXPATHLEN - 1) {
+ exe_path[len] = '\0';
+ return Path(std::string(exe_path));
+ }
+#elif defined(HAVE_DLFCN_H)
// Use dladdr to get executable path if available.
-#ifdef HAVE_DLFCN_H
Dl_info DLInfo;
int err = dladdr(MainAddr, &DLInfo);
if (err != 0)