[llvm-commits] [llvm] r48328 - /llvm/trunk/lib/System/Unix/Path.inc

Chris Lattner sabre at nondot.org
Wed Mar 12 22:22:05 PDT 2008


Author: lattner
Date: Thu Mar 13 00:22:05 2008
New Revision: 48328

URL: http://llvm.org/viewvc/llvm-project?rev=48328&view=rev
Log:
Fix Path::GetMainExecutable on cygwin, patch by Sam Bishop.

Modified:
    llvm/trunk/lib/System/Unix/Path.inc

Modified: llvm/trunk/lib/System/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Path.inc?rev=48328&r1=48327&r2=48328&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Path.inc (original)
+++ llvm/trunk/lib/System/Unix/Path.inc Thu Mar 13 00:22:05 2008
@@ -251,8 +251,17 @@
 /// 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)





More information about the llvm-commits mailing list