diff --git a/CMakeLists.txt b/CMakeLists.txt index 49e7b0acd8..da60d1095f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,6 +344,12 @@ if (NOT HAVE_STRNLEN) message(FATAL_ERROR "this compiler/environment isn't supported, the function strnlen is missing!") endif() +include (CheckFunctionExists) +check_symbol_exists(getexecpath unistd.h HAVE_GETEXECPATH) +if (HAVE_GETEXECPATH) + add_definitions(-DHAVE_GETEXECPATH) +endif() + ### Add Link-Time-Optimization flags, if supported (GCC >= 4.5) and enabled option(LTO "Link Time Optimizations (LTO)" FALSE) if (LTO) diff --git a/rts/System/Platform/Misc.cpp b/rts/System/Platform/Misc.cpp index e78c15dd39..ab3eb32d63 100644 --- a/rts/System/Platform/Misc.cpp +++ b/rts/System/Platform/Misc.cpp @@ -168,6 +168,7 @@ namespace Platform // Mac OS X: _NSGetExecutablePath() (man 3 dyld) // Linux: readlink /proc/self/exe // Solaris: getexecname() + // OpenBSD: getexecpath() // FreeBSD: sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1 // BSD with procfs: readlink /proc/curproc/file // Windows: GetModuleFileName() with hModule = NULL @@ -212,6 +213,16 @@ namespace Platform procExeFilePath = path; + #elif defined(__OpenBSD__) && defined(HAVE_GETEXECPATH) + char path[PATH_MAX]; + + if (getexecpath(path, sizeof(path)) == 0) { + procExeFilePath = path; + } else { + error = "[openbsd] execve(2) could not determine the executable pathname"; + } + + #elif defined(__FreeBSD__) const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; const long maxpath = pathconf("/", _PC_PATH_MAX);