From 76faee71a59f275581547555855b1205bf41d153 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 20 Nov 2020 14:11:03 -0600 Subject: [PATCH] Unify handling of BSD systems where applicable --- src/common.cpp | 10 +++++----- src/common.h | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common.cpp b/src/common.cpp index 4d2521fb4..af86e9faa 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -34,7 +34,7 @@ #include #endif -#ifdef __FreeBSD__ +#ifdef __BSD__ #include #elif defined(__APPLE__) #include @@ -1994,10 +1994,10 @@ 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(__FreeBSD__) - // FreeBSD does not have /proc by default, but it can be mounted as procfs via the - // Linux compatibility layer. Per sysctl(3), passing in a process ID of -1 returns - // the value for the current process. +#elif defined(__BSD__) + // 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. size_t buff_size = sizeof buff; int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; int result = sysctl(name, sizeof(name) / sizeof(int), buff, &buff_size, nullptr, 0); diff --git a/src/common.h b/src/common.h index b97ebe976..ba6a2ae55 100644 --- a/src/common.h +++ b/src/common.h @@ -22,6 +22,11 @@ #include "fallback.h" // IWYU pragma: keep #include "maybe.h" +// Create a generic define for all BSD platforms +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#define __BSD__ +#endif + // PATH_MAX may not exist. #ifndef PATH_MAX #define PATH_MAX 4096