From 75076106b95e32098b96f505358c0176fbcb074b Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Mon, 7 Jan 2019 18:31:15 -0600 Subject: [PATCH] Implement getCurrentExecutableLocation() on FreeBSD (#3688) --- src/utils/separate_process.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/utils/separate_process.cpp b/src/utils/separate_process.cpp index 19ec9b924..88193a28f 100644 --- a/src/utils/separate_process.cpp +++ b/src/utils/separate_process.cpp @@ -34,6 +34,11 @@ # include #endif +#ifdef __FreeBSD__ +#include +#include +#endif + #ifdef ANDROID #include #include @@ -58,6 +63,15 @@ std::string SeparateProcess::getCurrentExecutableLocation() return file_manager->getFileSystem()->getAbsolutePath(path).c_str(); } return ""; +#elif defined (__FreeBSD__) + char path[PATH_MAX]; + size_t len = PATH_MAX; + const int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + if (sysctl(&mib[0], 4, &path, &len, NULL, 0) == 0) + { + return file_manager->getFileSystem()->getAbsolutePath(path).c_str(); + } + return ""; #else // Assume Linux return file_manager->getFileSystem()->getAbsolutePath("/proc/self/exe")