diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-03-13 05:22:05 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-03-13 05:22:05 +0000 |
| commit | 02e727ff8897cab697d02e2620c66ecc86f6c2a0 (patch) | |
| tree | e4ec2e128dd836076e3a35dabfc58bc15b5c5d5e /llvm/lib | |
| parent | 4dec91222ad5563781a4c731b02a95ab2acbd725 (diff) | |
| download | bcm5719-llvm-02e727ff8897cab697d02e2620c66ecc86f6c2a0.tar.gz bcm5719-llvm-02e727ff8897cab697d02e2620c66ecc86f6c2a0.zip | |
Fix Path::GetMainExecutable on cygwin, patch by Sam Bishop.
llvm-svn: 48328
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/System/Unix/Path.inc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc index 8e76b543ff3..e11213294c6 100644 --- a/llvm/lib/System/Unix/Path.inc +++ b/llvm/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) |

