diff options
author | Chris Lattner <sabre@nondot.org> | 2008-03-03 02:55:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-03-03 02:55:43 +0000 |
commit | 1a091447f495bcf14a182e5960236db5f3adfede (patch) | |
tree | 6f7b39c16ee2d790cfad1277d483fd19d12322a9 /lib/System/Unix | |
parent | 53b727791729c5fc1ea5e40dd41fe93bfcde0288 (diff) |
Stub out a Path::GetMainExecutable call to find the path to the
main executable of a program. This needs to be implemented on windows.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47835 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index c8bdd088c3..8e76b543ff 100644 --- a/lib/System/Unix/Path.inc +++ b/lib/System/Unix/Path.inc @@ -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 @@ Path::GetCurrentDirectory() { 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 |