Explicitly check for KERN_PROC_PATHNAME

While FreeBSD, DragonflyBSD, and NetBSD have KERN_PROC_PATHNAME,
OpenBSD does not.
This commit is contained in:
Mahmoud Al-Qudsi
2020-11-20 15:49:57 -06:00
parent 01f239188d
commit 3699e50e00

View File

@@ -1995,7 +1995,7 @@ std::string get_executable_path(const char *argv0) {
// https://opensource.apple.com/source/adv_cmds/adv_cmds-163/ps/print.c
uint32_t buffSize = sizeof buff;
if (_NSGetExecutablePath(buff, &buffSize) == 0) return std::string(buff);
#elif defined(__BSD__)
#elif defined(__BSD__) && defined(KERN_PROC_PATHNAME)
// BSDs do not have /proc by default, (although it can be mounted as procfs via the Linux
// compatibility layer). We can use sysctl instead: per sysctl(3), passing in a process ID of -1
// returns the value for the current process.