Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions rts/System/Platform/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down