From 693313229d9b7f224b83706141b1de26cdd86515 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 29 Jul 2017 12:13:00 +0200
Subject: g_dbus_message_print: use B_PRIiDEV on Haiku

because Haiku doesn't define major() and minor()

diff --git a/gio/gdbusmessage.c b/gio/gdbusmessage.c
index bc9386e..c71c8aa 100644
--- a/gio/gdbusmessage.c
+++ b/gio/gdbusmessage.c
@@ -35,8 +35,12 @@
 #elif MAJOR_IN_TYPES
 #include <sys/types.h>
 #else
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#else
 #define MAJOR_MINOR_NOT_FOUND 1
 #endif
+#endif
 
 #include "gdbusutils.h"
 #include "gdbusmessage.h"
@@ -3571,8 +3575,14 @@ g_dbus_message_print (GDBusMessage *message,
               if (fstat (fds[n], &statbuf) == 0)
                 {
 #ifndef MAJOR_MINOR_NOT_FOUND                       
+#ifdef __HAIKU__
+                  g_string_append_printf (fs, "%s" "dev=%" B_PRIiDEV, fs->len > 0 ? "," : "",
+                                          statbuf.st_dev);
+#else
+
                   g_string_append_printf (fs, "%s" "dev=%d:%d", fs->len > 0 ? "," : "",
                                           (gint) major (statbuf.st_dev), (gint) minor (statbuf.st_dev));
+#endif
 #endif                  
                   g_string_append_printf (fs, "%s" "mode=0%o", fs->len > 0 ? "," : "",
                                           (guint) statbuf.st_mode);
@@ -3583,9 +3593,14 @@ g_dbus_message_print (GDBusMessage *message,
                   g_string_append_printf (fs, "%s" "gid=%u", fs->len > 0 ? "," : "",
                                           (guint) statbuf.st_gid);
 #ifndef MAJOR_MINOR_NOT_FOUND                     
+#ifdef __HAIKU__
+                  g_string_append_printf (fs, "%s" "rdev=%" B_PRIiDEV, fs->len > 0 ? "," : "",
+                                          statbuf.st_rdev);
+#else
                   g_string_append_printf (fs, "%s" "rdev=%d:%d", fs->len > 0 ? "," : "",
                                           (gint) major (statbuf.st_rdev), (gint) minor (statbuf.st_rdev));
 #endif                  
+#endif
                   g_string_append_printf (fs, "%s" "size=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
                                           (guint64) statbuf.st_size);
                   g_string_append_printf (fs, "%s" "atime=%" G_GUINT64_FORMAT, fs->len > 0 ? "," : "",
-- 
2.30.2


From 118dcaca817c9c6f017402280c05498dbb7d38e4 Mon Sep 17 00:00:00 2001
From: Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Date: Mon, 23 Aug 2021 19:31:38 +0000
Subject: gunixmounts.c: Add Haiku support


diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 32b9362..206f856 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -58,6 +58,9 @@
 #endif
 #include <sys/mount.h>
 #endif
+#ifdef __HAIKU__
+#include <kernel/fs_info.h>
+#endif
 
 #ifndef O_BINARY
 #define O_BINARY 0
@@ -956,6 +959,49 @@ _g_get_unix_mounts (void)
   return return_list;
 }
 
+/* Haiku {{{2 */
+#elif defined(__HAIKU__)
+
+static const char *
+get_mtab_monitor_file (void)
+{
+  return NULL;
+}
+
+static GList *
+_g_get_unix_mounts (void)
+{
+  int32 pos = 0;
+  GList* return_list = NULL;
+  struct fs_info info;
+  GUnixMountEntry* mount_entry;
+
+  while (1)
+    {
+      dev_t dev = next_dev (&pos);
+      if (dev < 0)
+        break;
+
+      if (fs_stat_dev (dev, &info) < 0)
+        continue;
+
+      mount_entry = g_new0 (GUnixMountEntry, 1);
+
+      mount_entry->mount_path = g_strdup (info.volume_name);
+      mount_entry->device_path = g_strdup (info.device_name);
+      mount_entry->filesystem_type = g_strdup (info.fsh_name);
+
+      mount_entry->is_read_only = (info.flags & B_FS_IS_READONLY) ? TRUE : FALSE;
+      mount_entry->is_system_internal = (info.flags & B_FS_IS_REMOVABLE) ? FALSE : TRUE;
+
+      return_list = g_list_prepend (return_list, mount_entry);
+    }
+
+  return_list = g_list_reverse (return_list);
+
+  return return_list;
+}
+
 /* QNX {{{2 */
 #elif defined (HAVE_QNX)
 
@@ -1488,16 +1534,8 @@ _g_get_unix_mount_points (void)
   
   return g_list_reverse (return_list);
 }
-/* Interix {{{2 */
-#elif defined(__INTERIX)
-static GList *
-_g_get_unix_mount_points (void)
-{
-  return _g_get_unix_mounts ();
-}
-
-/* QNX {{{2 */
-#elif defined (HAVE_QNX)
+/* Interix, QNX, Haiku {{{2 */
+#elif defined (__INTERIX) || defined (HAVE_QNX) || defined (__HAIKU__)
 static GList *
 _g_get_unix_mount_points (void)
 {
-- 
2.30.2


From fbb32f7234f051b16c0fe3cbbbafaf5782bb5669 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 29 Jul 2017 12:32:14 +0200
Subject: glib/gutils.c: on Haiku define load_user_special_dirs()

use find_directory() from SupportDefs.h

diff --git a/glib/gutils.c b/glib/gutils.c
index dad1625..8f1f29d 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -75,6 +75,10 @@
 #include "gwin32.h"
 #endif
 
+#if defined(__HAIKU__)
+#include <FindDirectory.h>
+#include <fs_info.h>
+#endif
 
 /**
  * SECTION:misc_utils
@@ -1960,6 +1964,35 @@ load_user_special_dirs (void)
   load_user_special_dirs_macos (g_user_special_dirs);
 }
 
+#elif defined(__HAIKU__)
+static void
+load_user_special_dirs (void)
+{
+  char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+
+  dev_t volume = dev_for_path("/boot");
+  if (find_directory(B_DESKTOP_DIRECTORY, volume, false, path, sizeof(path))
+      == B_OK) {
+    g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_strdup(path);
+    g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = g_strdup(path);
+  } else {
+    g_user_special_dirs[G_USER_DIRECTORY_DOCUMENTS] = NULL;
+    g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = NULL;
+  }
+
+  if (find_directory(B_USER_DIRECTORY, volume, false, path, sizeof(path))
+      == B_OK) {
+    g_user_special_dirs[G_USER_DIRECTORY_DOCUMENTS] = g_strdup(path);
+  } else
+    g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = NULL;
+
+  g_user_special_dirs[G_USER_DIRECTORY_MUSIC] = NULL;
+  g_user_special_dirs[G_USER_DIRECTORY_PICTURES] = NULL;
+  g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = NULL;
+  g_user_special_dirs[G_USER_DIRECTORY_TEMPLATES] = NULL;
+  g_user_special_dirs[G_USER_DIRECTORY_VIDEOS] = NULL;
+}
+
 #elif defined(G_OS_WIN32)
 
 static void
-- 
2.30.2


From 2b1f8901948b1d1378c795cb3b7a8f332e17c32b Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 23 Nov 2019 20:10:10 +0100
Subject: Haiku patch for x86


diff --git a/tests/mapping-test.c b/tests/mapping-test.c
index ad776fa..49d2ea4 100644
--- a/tests/mapping-test.c
+++ b/tests/mapping-test.c
@@ -182,6 +182,10 @@ test_private (void)
   g_message ("test_private: ok");
 }
 
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#endif
+
 static void
 test_child_private (gchar *argv0)
 {
@@ -208,7 +212,11 @@ test_child_private (gchar *argv0)
   signal (SIGUSR1, handle_usr1);
 #endif
 
+#ifdef __HAIKU__
+  g_snprintf (pid, sizeof(pid), B_PRId32, getpid ());
+#else
   g_snprintf (pid, sizeof(pid), "%d", getpid ());
+#endif
   child_argv[0] = argv0;
   child_argv[1] = "mapchild";
   child_argv[2] = pid;
-- 
2.30.2


From 42a4988965cf166fdd07f66d6c87953df834a257 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 17 Aug 2021 08:29:48 +0000
Subject: Fix network detection


diff --git a/gio/meson.build b/gio/meson.build
index 49a37a7..8d77588 100644
--- a/gio/meson.build
+++ b/gio/meson.build
@@ -21,6 +21,7 @@ if host_system not in ['windows', 'android']
                         int qclass = C_IN;''',
                      name : 'C_IN in public headers (no arpa/nameser_compat.h needed)')
     if cc.compiles('''#include <sys/types.h>
+                      #include <stdint.h>
                       #include <arpa/nameser.h>
                       #include <arpa/nameser_compat.h>
                       int qclass = C_IN;''',
@@ -41,6 +42,7 @@ if host_system != 'windows'
                         return res_query("test", 0, 0, (void *)0, 0);
                       }'''
   res_query_test_full = '''#include <sys/types.h>
+                           #include <stdint.h>
                            #include <netinet/in.h>
                            #include <arpa/nameser.h>
                         ''' + res_query_test
@@ -54,6 +56,9 @@ if host_system != 'windows'
     elif cc.links(res_query_test, args : '-lsocket', name : 'res_query() in -lsocket')
       network_libs += [ cc.find_library('socket') ]
       network_args += [ '-lsocket' ]
+    elif cc.links(res_query_test, args : '-lnetwork', name : 'res_query() in -lnetwork')
+      network_libs += [ cc.find_library('network') ]
+      network_args += [ '-lnetwork' ]
     else
       error('Could not find res_query()')
     endif
-- 
2.30.2


From 2a0d2857003ef35879dd05228219fde9cefe47f3 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Fri, 28 Jan 2022 10:49:17 +1000
Subject: Use find_directory if XDG vars not found


diff --git a/gio/xdgmime/xdgmime.c b/gio/xdgmime/xdgmime.c
index 9bb93f7..31bae11 100644
--- a/gio/xdgmime/xdgmime.c
+++ b/gio/xdgmime/xdgmime.c
@@ -41,6 +41,11 @@
 #include <unistd.h>
 #include <assert.h>
 
+#if defined(__HAIKU__)
+#include <FindDirectory.h>
+#include <fs_info.h>
+#endif
+
 typedef struct XdgDirTimeList XdgDirTimeList;
 typedef struct XdgCallbackList XdgCallbackList;
 
@@ -234,6 +239,25 @@ xdg_init_dirs (void)
   home = getenv ("HOME");
   xdg_data_dirs = getenv ("XDG_DATA_DIRS");
 
+#ifdef __HAIKU__
+  {
+    char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+    dev_t volume = dev_for_path("/boot");
+
+    if (xdg_data_home == NULL)
+      if (find_directory(B_USER_NONPACKAGED_DATA_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+        xdg_data_home = strdup(path);
+
+    if (home == NULL)
+      if (find_directory(B_USER_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+        home = strdup(path);
+
+    if (xdg_data_dirs == NULL)
+      if (find_directory(B_SYSTEM_DATA_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+        xdg_data_dirs = strdup(path);
+  }
+#endif
+
   if (xdg_data_dirs == NULL)
     xdg_data_dirs = "/usr/local/share/:/usr/share/";
 
diff --git a/glib/gutils.c b/glib/gutils.c
index 8f1f29d..b609825 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -1709,6 +1709,13 @@ g_build_user_data_dir (void)
 #ifdef G_OS_WIN32
   else
     data_dir = get_special_folder (CSIDL_LOCAL_APPDATA);
+#elif defined(__HAIKU__)
+  else {
+  	char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+    dev_t volume = dev_for_path("/boot");
+    if (find_directory(B_USER_NONPACKAGED_DATA_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+      data_dir = g_strdup(path);
+  }
 #endif
   if (!data_dir || !data_dir[0])
     {
@@ -1773,6 +1780,13 @@ g_build_user_config_dir (void)
 #ifdef G_OS_WIN32
   else
     config_dir = get_special_folder (CSIDL_LOCAL_APPDATA);
+#elif defined(__HAIKU__)
+  else {
+  	char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+    dev_t volume = dev_for_path("/boot");
+    if (find_directory(B_USER_SETTINGS_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+      config_dir = g_strdup(path);
+  }
 #endif
   if (!config_dir || !config_dir[0])
     {
@@ -1836,6 +1850,13 @@ g_build_user_cache_dir (void)
 #ifdef G_OS_WIN32
   else
     cache_dir = get_special_folder (CSIDL_INTERNET_CACHE);
+#elif defined(__HAIKU__)
+  else {
+  	char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+    dev_t volume = dev_for_path("/boot");
+    if (find_directory(B_USER_CACHE_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+      cache_dir = g_strdup(path);
+  }
 #endif
   if (!cache_dir || !cache_dir[0])
     {
@@ -2535,7 +2556,16 @@ g_build_system_data_dirs (void)
    */
 #ifndef G_OS_WIN32
   if (!data_dirs || !data_dirs[0])
+#if defined(__HAIKU__)
+    {
+  	  char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+      dev_t volume = dev_for_path("/boot");
+      if (find_directory(B_SYSTEM_DATA_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+        data_dirs = g_strdup(path);
+    }
+#else
     data_dirs = "/usr/local/share/:/usr/share/";
+#endif
 
   data_dir_vector = g_strsplit (data_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
 #else
@@ -2630,6 +2660,20 @@ g_build_system_config_dirs (void)
 
       g_free (special_conf_dirs);
     }
+#elif defined(__HAIKU__)
+  if (conf_dirs)
+    {
+      conf_dir_vector = g_strsplit (conf_dirs, G_SEARCHPATH_SEPARATOR_S, 0);
+    }
+  else
+    {
+      char path[B_PATH_NAME_LENGTH + B_FILE_NAME_LENGTH];
+      dev_t volume = dev_for_path("/boot");
+      if (find_directory(B_SYSTEM_SETTINGS_DIRECTORY, volume, false, path, sizeof(path)) == B_OK)
+        conf_dir_vector = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, 0);
+      else 
+        conf_dir_vector = g_strsplit ("", G_SEARCHPATH_SEPARATOR_S, 0);
+    }
 #else
   if (!conf_dirs || !conf_dirs[0])
     conf_dirs = "/etc/xdg";
-- 
2.30.2

