From a20d75b432680c844cdd831dcc426861f30ac91e Mon Sep 17 00:00:00 2001
From: miqlas <zmizsei@extrowerk.com>
Date: Thu, 3 Jan 2019 14:53:01 +0300
Subject: Fix build on Haiku


diff --git a/src/core/poll_manager.cc b/src/core/poll_manager.cc
old mode 100755
new mode 100644
index 1a3a0a5..1818d78
--- a/src/core/poll_manager.cc
+++ b/src/core/poll_manager.cc
@@ -36,6 +36,10 @@
 
 #include "config.h"
 
+#ifdef __HAIKU__
+#include <sys/select.h>
+#endif
+
 #include <stdexcept>
 #include <unistd.h>
 #include <torrent/exceptions.h>
diff --git a/src/input/path_input.cc b/src/input/path_input.cc
old mode 100755
new mode 100644
index caf1e17..607cfb7
--- a/src/input/path_input.cc
+++ b/src/input/path_input.cc
@@ -48,6 +48,12 @@
 
 #include "path_input.h"
 
+#ifndef DT_DIR
+/* dirent.d_type is a BSD extension, not part of POSIX */
+#include <sys/stat.h>
+#include <dirent.h>
+#endif
+
 namespace input {
 
 PathInput::PathInput() :
@@ -75,7 +81,7 @@ PathInput::pressed(int key) {
 
 struct _transform_filename {
   void operator () (utils::directory_entry& entry) {
-#ifdef __sun__
+#if defined (__sun__) || defined(__HAIKU__)
     if (entry.d_type & S_IFDIR)
 #else
     if (entry.d_type == DT_DIR)
diff --git a/src/utils/directory.cc b/src/utils/directory.cc
index f934aeb..73d23f9 100755
--- a/src/utils/directory.cc
+++ b/src/utils/directory.cc
@@ -46,6 +46,10 @@
 
 #include "directory.h"
 
+#ifdef __HAIKU__
+struct stat st;
+#endif
+
 namespace utils {
 
 // Keep this?
@@ -89,7 +93,12 @@ Directory::update(int flags) {
 #else
     itr->d_fileno = entry->d_fileno;
     itr->d_reclen = entry->d_reclen;
+    #ifdef __HAIKU__
+    	lstat(rak::path_expand(m_path).c_str(), &st);
+		itr->d_type   = st.st_mode;
+	#else
     itr->d_type   = entry->d_type;
+    #endif
 #endif
 
 #ifdef DIRENT_NAMLEN_EXISTS_FOOBAR
diff --git a/src/utils/directory.h b/src/utils/directory.h
index ec8027b..f11a418 100755
--- a/src/utils/directory.h
+++ b/src/utils/directory.h
@@ -41,6 +41,10 @@
 #include <vector>
 #include <inttypes.h>
 
+#ifdef __HAIKU__
+#define d_fileno d_ino
+#endif
+
 namespace utils {
 
 struct directory_entry {
diff --git a/src/utils/socket_fd.cc b/src/utils/socket_fd.cc
old mode 100755
new mode 100644
index e30594d..6cb58ee
--- a/src/utils/socket_fd.cc
+++ b/src/utils/socket_fd.cc
@@ -71,9 +71,11 @@ SocketFd::set_priority(priority_type p) {
   check_valid();
   int opt = p;
 
+#ifndef __HAIKU__
   if (m_ipv6_socket)
-    return setsockopt(m_fd, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) == 0;
-  else
+     return setsockopt(m_fd, IPPROTO_IPV6, IPV6_TCLASS, &opt, sizeof(opt)) == 0;
+   else
+#endif
     return setsockopt(m_fd, IPPROTO_IP, IP_TOS, &opt, sizeof(opt)) == 0;
 }
 
-- 
2.19.1

