From cdf1c4e7997a54d7a6c8256bfbac7ff83f6d78a2 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Fri, 5 Sep 2014 14:57:25 +0000
Subject: haiku patch 1


diff --git a/libtransmission/platform-quota.c b/libtransmission/platform-quota.c
index 9f33b62..81c114b 100644
--- a/libtransmission/platform-quota.c
+++ b/libtransmission/platform-quota.c
@@ -12,7 +12,7 @@
 
 #include <event2/util.h> /* evutil_ascii_strcasecmp() */
 
-#ifndef _WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
 #include <unistd.h> /* getuid() */
 #include <sys/types.h> /* types needed by quota.h */
 #if defined(__FreeBSD__) || defined(__OpenBSD__)
@@ -73,7 +73,7 @@
 ****
 ***/
 
-#ifndef _WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
 
 static char const* getdev(char const* path)
 {
@@ -434,7 +434,7 @@ static int64_t tr_getQuotaFreeSpace(struct tr_device_info const* info)
 {
     int64_t ret = -1;
 
-#ifndef _WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
 
     if (info->fstype != NULL && evutil_ascii_strcasecmp(info->fstype, "xfs") == 0)
     {
@@ -500,7 +500,7 @@ struct tr_device_info* tr_device_info_create(char const* path)
     info = tr_new0(struct tr_device_info, 1);
     info->path = tr_strdup(path);
 
-#ifndef _WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
     info->device = tr_strdup(getblkdev(path));
     info->fstype = tr_strdup(getfstype(path));
 #endif
-- 
2.27.0


From e714b45b9df1e3e4a9da5208232bc9df17a85eca Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Fri, 5 Sep 2014 14:57:25 +0000
Subject: No HAS_IP_MREQN for Haiku


diff --git a/third-party/miniupnpc/minissdpc.c b/third-party/miniupnpc/minissdpc.c
index 8eee2e9..c171bb6 100644
--- a/third-party/miniupnpc/minissdpc.c
+++ b/third-party/miniupnpc/minissdpc.c
@@ -67,7 +67,7 @@ struct sockaddr_un {
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 
-#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__)
+#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__) && !defined(__HAIKU__)
 #define HAS_IP_MREQN
 #endif
 
-- 
2.27.0


From 98c7a6e59c102b20290a129a0f1c6c493578690d Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Fri, 5 Sep 2014 14:57:25 +0000
Subject: fix for atoui


diff --git a/third-party/miniupnpc/portlistingparse.c b/third-party/miniupnpc/portlistingparse.c
index 55859f2..c05f4a1 100644
--- a/third-party/miniupnpc/portlistingparse.c
+++ b/third-party/miniupnpc/portlistingparse.c
@@ -31,7 +31,7 @@ static const struct {
 
 /* Helper function */
 static UNSIGNED_INTEGER
-atoui(const char * p, int l)
+my_atoui(const char * p, int l)
 {
 	UNSIGNED_INTEGER r = 0;
 	while(l > 0 && *p)
@@ -107,7 +107,7 @@ data(void * d, const char * data, int l)
 		pm->remoteHost[l] = '\0';
 		break;
 	case NewExternalPort:
-		pm->externalPort = (unsigned short)atoui(data, l);
+		pm->externalPort = (unsigned short)my_atoui(data, l);
 		break;
 	case NewProtocol:
 		if(l > 3)
@@ -116,21 +116,21 @@ data(void * d, const char * data, int l)
 		pm->protocol[l] = '\0';
 		break;
 	case NewInternalPort:
-		pm->internalPort = (unsigned short)atoui(data, l);
+		pm->internalPort = (unsigned short)my_atoui(data, l);
 		break;
 	case NewInternalClient:
 		memcpy(pm->internalClient, data, l);
 		pm->internalClient[l] = '\0';
 		break;
 	case NewEnabled:
-		pm->enabled = (unsigned char)atoui(data, l);
+		pm->enabled = (unsigned char)my_atoui(data, l);
 		break;
 	case NewDescription:
 		memcpy(pm->description, data, l);
 		pm->description[l] = '\0';
 		break;
 	case NewLeaseTime:
-		pm->leaseTime = atoui(data, l);
+		pm->leaseTime = my_atoui(data, l);
 		break;
 	default:
 		break;
-- 
2.27.0


From b28b5e7369dce6250038968cccecd14d957c77ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20Mizsei?= <zmizsei@extrowerk.com>
Date: Sat, 4 Nov 2017 14:24:02 +0100
Subject: Haiku supporting patches


diff --git a/CMakeLists.txt b/CMakeLists.txt
index 62bf87b..21ec195 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -508,6 +508,13 @@ if(HAVE_LIBM)
     set(LIBM_LIBRARY m)
 endif()
 
+if (HAIKU)
+	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DB_USE_POSITIVE_POSIX_ERRORS")
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DB_USE_POSITIVE_POSIX_ERRORS")
+    set(NETWORKING_LIBRARY network)
+    set(HAIKU_SUPPORT_LIBRARY posix_error_mapper)
+endif()
+
 set(TR_NETWORK_LIBRARIES)
 if(WIN32)
     list(APPEND TR_NETWORK_LIBRARIES iphlpapi ws2_32)
diff --git a/libtransmission/CMakeLists.txt b/libtransmission/CMakeLists.txt
index 672cd0e..9b7b8c7 100644
--- a/libtransmission/CMakeLists.txt
+++ b/libtransmission/CMakeLists.txt
@@ -274,6 +274,8 @@ target_link_libraries(${TR_NAME}
     ${LIBINTL_LIBRARY}
     ${LIBM_LIBRARY}
     ${TR_NETWORK_LIBRARIES}
+    ${NETWORKING_LIBRARY}
+    ${HAIKU_SUPPORT_LIBRARY}
 )
 
 if(ICONV_FOUND)
-- 
2.27.0


From dfe6d1a5315a54c1fc3b064b670842a13e19c956 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 10 Jun 2020 20:35:03 +1000
Subject: Use haiku int types for UTP library


diff --git a/third-party/libutp/utypes.h b/third-party/libutp/utypes.h
index 79bafcd..676a088 100644
--- a/third-party/libutp/utypes.h
+++ b/third-party/libutp/utypes.h
@@ -2,7 +2,10 @@
 #define __UTYPES_H__
 
 // standard types
-typedef unsigned char byte;
+typedef unsigned char byte;
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#else
 typedef unsigned char uint8;
 typedef signed char int8;
 typedef unsigned short uint16;
@@ -17,6 +20,7 @@ typedef signed __int64 int64;
 #else
 typedef unsigned long long uint64;
 typedef long long int64;
+#endif
 #endif
 
 /* compile-time assert */
@@ -35,7 +39,7 @@ CASSERT(8 == sizeof(int64), sizeof_int64_is_8)
 typedef const char * cstr;
 typedef char * str;
 
-#ifndef __cplusplus
+#if !defined(__cplusplus) && !defined(__HAIKU__)
 typedef uint8 bool;
 #endif
 
-- 
2.27.0


From da0110403f7bcf0b5338fedf5eaf7e2d83ac7483 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zolt=C3=A1n=20Mizsei?= <zmizsei@extrowerk.com>
Date: Mon, 29 Jun 2020 07:46:02 +0200
Subject: Test for libnetwork


diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21ec195..bb2fd1f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -519,12 +519,12 @@ set(TR_NETWORK_LIBRARIES)
 if(WIN32)
     list(APPEND TR_NETWORK_LIBRARIES iphlpapi ws2_32)
 else()
-    tr_select_library("c;socket;net" socket "" LIB)
+    tr_select_library("c;socket;net;network" socket "" LIB)
     if(NOT LIB MATCHES "^(|c)$")
         list(APPEND TR_NETWORK_LIBRARIES ${LIB})
     endif()
 
-    tr_select_library("c;nsl;bind" gethostbyname "" LIB)
+    tr_select_library("c;nsl;bind;network" gethostbyname "" LIB)
     if(NOT LIB MATCHES "^(|c)$")
         list(APPEND TR_NETWORK_LIBRARIES ${LIB})
     endif()
-- 
2.27.0

