From bffa49d630c70d004d4f205c94b0aca544f9e2fe Mon Sep 17 00:00:00 2001
From: Tobias Kortkamp <t@tobik.me>
Date: Wed, 29 Dec 2021 15:57:52 +0000
Subject: [PATCH] haiku: use BPathFinder to find runtime and settings dirs

---
 src/main.cc | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/main.cc b/src/main.cc
index 6da6e64..30760ee 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -35,6 +35,11 @@
 #include <unistd.h>
 #include <pwd.h>
 
+#ifdef __HAIKU__
+#include <Path.h>
+#include <PathFinder.h>
+#endif
+
 namespace Kakoune
 {
 
@@ -170,6 +175,13 @@ String runtime_directory()
     if (stat(relpath, &st) == 0 and S_ISDIR(st.st_mode))
         return real_path(relpath);
 
+#ifdef __HAIKU__
+    BPath path;
+    BPathFinder pathFinder;
+    if (pathFinder.FindPath(B_FIND_PATH_DATA_DIRECTORY, "kak", B_FIND_PATH_EXISTING_ONLY, path) == B_OK)
+        return path.Path();
+#endif
+
     return "/usr/share/kak";
 }
 
@@ -177,6 +189,14 @@ String config_directory()
 {
     if (StringView kak_cfg_dir = getenv("KAKOUNE_CONFIG_DIR"); not kak_cfg_dir.empty())
         return kak_cfg_dir.str();
+
+#ifdef __HAIKU__
+    BPath path;
+    BPathFinder pathFinder;
+    if (pathFinder.FindPath(B_FIND_PATH_SETTINGS_DIRECTORY, "kak", B_FIND_PATH_EXISTING_ONLY, path) == B_OK)
+        return path.Path();
+#endif
+
     if (StringView xdg_cfg_home = getenv("XDG_CONFIG_HOME"); not xdg_cfg_home.empty())
         return format("{}/kak", xdg_cfg_home);
     return format("{}/.config/kak", homedir());
-- 
2.30.2

