[llvm-commits] [llvm] r47835 - in /llvm/trunk: include/llvm/System/Path.h lib/System/Unix/Path.inc lib/System/Win32/Path.inc

Chris Lattner sabre at nondot.org
Sun Mar 2 18:55:44 PST 2008


Author: lattner
Date: Sun Mar  2 20:55:43 2008
New Revision: 47835

URL: http://llvm.org/viewvc/llvm-project?rev=47835&view=rev
Log:
Stub out a Path::GetMainExecutable call to find the path to the
main executable of a program.  This needs to be implemented on windows.

Modified:
    llvm/trunk/include/llvm/System/Path.h
    llvm/trunk/lib/System/Unix/Path.inc
    llvm/trunk/lib/System/Win32/Path.inc

Modified: llvm/trunk/include/llvm/System/Path.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Path.h?rev=47835&r1=47834&r2=47835&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Path.h (original)
+++ llvm/trunk/include/llvm/System/Path.h Sun Mar  2 20:55:43 2008
@@ -161,6 +161,10 @@
       /// @returns The dynamic link library suffix for the current platform.
       /// @brief Return the dynamic link library suffix.
       static std::string GetDLLSuffix();
+    
+      /// GetMainExecutable - Return the path to the main executable, given the
+      /// value of argv[0] from program startup and the address of main itself.
+      static Path GetMainExecutable(const char *argv0, void *MainAddr);
 
       /// This is one of the very few ways in which a path can be constructed
       /// with a syntactically invalid name. The only *legal* invalid name is an

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

==============================================================================
--- llvm/trunk/lib/System/Unix/Path.inc (original)
+++ llvm/trunk/lib/System/Unix/Path.inc Sun Mar  2 20:55:43 2008
@@ -47,6 +47,10 @@
 # endif
 #endif
 
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
 // Put in a hack for Cygwin which falsely reports that the mkdtemp function
 // is available when it is not.
 #ifdef __CYGWIN__
@@ -244,6 +248,20 @@
   return Path(pathname);
 }
 
+/// 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) {
+  // Use dladdr to get executable path if available.
+#ifdef HAVE_DLFCN_H
+  Dl_info DLInfo;
+  int err = dladdr(MainAddr, &DLInfo);
+  if (err != 0)
+    return Path(std::string(DLInfo.dli_fname));
+#endif
+  return Path();
+}
+
+
 std::string
 Path::getBasename() const {
   // Find the last slash

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

==============================================================================
--- llvm/trunk/lib/System/Win32/Path.inc (original)
+++ llvm/trunk/lib/System/Win32/Path.inc Sun Mar  2 20:55:43 2008
@@ -214,6 +214,12 @@
   return Path(pathname);  
 }
 
+/// 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) {
+  return Path();
+}
+
 
 // FIXME: the above set of functions don't map to Windows very well.
 





More information about the llvm-commits mailing list