summaryrefslogtreecommitdiff
path: root/src/desktop/Window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/desktop/Window.cpp')
-rw-r--r--src/desktop/Window.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp
index 706d21cc..8a0e37a6 100644
--- a/src/desktop/Window.cpp
+++ b/src/desktop/Window.cpp
@@ -3,6 +3,11 @@
#include <hyprutils/animation/AnimatedVariable.hpp>
#include <re2/re2.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
#include <any>
#include <bit>
#include <string_view>
@@ -1203,6 +1208,10 @@ std::unordered_map<std::string, std::string> CWindow::getEnv() {
std::unordered_map<std::string, std::string> results;
+ std::vector<char> buffer;
+ size_t needle = 0;
+
+#if defined(__linux__)
//
std::string environFile = "/proc/" + std::to_string(PID) + "/environ";
std::ifstream ifs(environFile, std::ios::binary);
@@ -1210,13 +1219,25 @@ std::unordered_map<std::string, std::string> CWindow::getEnv() {
if (!ifs.good())
return {};
- std::vector<char> buffer;
- size_t needle = 0;
buffer.resize(512, '\0');
while (ifs.read(buffer.data() + needle, 512)) {
buffer.resize(buffer.size() + 512, '\0');
needle += 512;
}
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ENV, static_cast<int>(PID)};
+ size_t len = 0;
+
+ if (sysctl(mib, 4, nullptr, &len, nullptr, 0) < 0 || len == 0)
+ return {};
+
+ buffer.resize(len, '\0');
+
+ if (sysctl(mib, 4, buffer.data(), &len, nullptr, 0) < 0)
+ return {};
+
+ needle = len;
+#endif
if (needle <= 1)
return {};