aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System
diff options
context:
space:
mode:
Diffstat (limited to 'lib/System')
-rw-r--r--lib/System/Unix/Path.inc18
-rw-r--r--lib/System/Win32/Path.inc6
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index c8bdd08..8e76b54 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
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index ee3f622..0499e61 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -214,6 +214,12 @@ 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) {
+ return Path();
+}
+
// FIXME: the above set of functions don't map to Windows very well.