forked from OSchip/llvm-project
Stub out a Path::GetMainExecutable call to find the path to the
main executable of a program. This needs to be implemented on windows. llvm-svn: 47835
This commit is contained in:
parent
c16b6b2eab
commit
e209be4985
|
@ -162,6 +162,10 @@ namespace sys {
|
||||||
/// @brief Return the dynamic link library suffix.
|
/// @brief Return the dynamic link library suffix.
|
||||||
static std::string GetDLLSuffix();
|
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
|
/// 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
|
/// with a syntactically invalid name. The only *legal* invalid name is an
|
||||||
/// empty one. Other invalid names are not permitted. Empty paths are
|
/// empty one. Other invalid names are not permitted. Empty paths are
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_DLFCN_H
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Put in a hack for Cygwin which falsely reports that the mkdtemp function
|
// Put in a hack for Cygwin which falsely reports that the mkdtemp function
|
||||||
// is available when it is not.
|
// is available when it is not.
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
|
@ -244,6 +248,20 @@ Path::GetCurrentDirectory() {
|
||||||
return Path(pathname);
|
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
|
std::string
|
||||||
Path::getBasename() const {
|
Path::getBasename() const {
|
||||||
// Find the last slash
|
// Find the last slash
|
||||||
|
|
|
@ -214,6 +214,12 @@ Path::GetCurrentDirectory() {
|
||||||
return Path(pathname);
|
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.
|
// FIXME: the above set of functions don't map to Windows very well.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue