Hi,

I had a look at porting Twinkle to Haiku, and it seems ucommon is a
dependency.

I managed to build it on Haiku without too much trouble. See attached
patchset.

mlock: We currently don't have it. We have native calls alike so it
should be possible to add it someday.

libnetwork: the easiest way to hack it into was to fake it as libc (we
actually have libroot always linked in by default anyway which contains
libc).
Really, Those nested AC_CHECK_LIB should be replaced by AC_SEARCH_LIB.


Finally, our ifreq struct doesn't have named unions inside.

Things build but I didn't test anything yet.
From d4b74d78e5483b18a6d74212682b1324fe35d1c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <re...@free.fr>
Date: Sun, 24 Feb 2019 02:20:34 +0100
Subject: [PATCH 1/3] test for mlock (Haiku does not have it)

---
 cmake/config.cmake | 1 +
 configure.ac       | 6 +++++-
 corelib/mapped.cpp | 4 ++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cmake/config.cmake b/cmake/config.cmake
index d887f13a..e04b0d45 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -58,6 +58,7 @@ check_function_exists(waitpid HAVE_WAITPID)
 check_function_exists(wait4 HAVE_WAIT4)
 check_function_exists(setgroups HAVE_SETGROUPS)
 check_function_exists(strlcpy HAVE_STRLCPY)
+check_function_exists(mlocl HAVE_MLOCK)
 
 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
 check_include_files(strings.h HAVE_STRINGS_H)
diff --git a/configure.ac b/configure.ac
index 9bcaca5e..77bc9265 100644
--- a/configure.ac
+++ b/configure.ac
@@ -255,6 +255,10 @@ AC_CHECK_LIB($clib, stristr, [
     AC_DEFINE(HAVE_STRISTR, [1], [string istr])
 ])
 
+AC_CHECK_LIB($clib, mlock, [
+    AC_DEFINE(HAVE_MLOCK, [1], [mlock])
+])
+
 AC_CHECK_LIB($clib, sysconf, [
     AC_DEFINE(HAVE_SYSCONF, [1], [system config])
 ])
@@ -347,7 +351,7 @@ if test "$threading" = "none" ; then
     fi
 fi
 
-for func in ftok shm_open nanosleep clock_nanosleep clock_gettime strerror_r 
localtime_r gmtime_r posix_fadvise ftruncate pwrite setgroups setpgrp setlocale 
gettext execvp atexit realpath symlink readlink waitpid wait4 endgrent strlcpy; 
do
+for func in ftok shm_open nanosleep clock_nanosleep clock_gettime strerror_r 
localtime_r gmtime_r posix_fadvise ftruncate pwrite setgroups setpgrp setlocale 
gettext execvp atexit realpath symlink readlink waitpid wait4 endgrent strlcpy 
mlock; do
     found="no"
     AC_CHECK_FUNC($func,[
         found=$func
diff --git a/corelib/mapped.cpp b/corelib/mapped.cpp
index f23e2f8c..87839df1 100644
--- a/corelib/mapped.cpp
+++ b/corelib/mapped.cpp
@@ -354,7 +354,9 @@ void MappedMemory::create(const char *fn, size_t len)
     ::close(fd);
     if(map != (caddr_t)MAP_FAILED) {
         size = mapsize = len;
+#ifdef HAVE_MLOCK
         mlock(map, mapsize);
+#endif
 #if INSERT_OFFSET > 0
         if(prot & PROT_WRITE) {
             size -= INSERT_OFFSET;
@@ -377,7 +379,9 @@ void MappedMemory::release()
     if(size) {
         if(use_mapping) {
             map -= INSERT_OFFSET;
+#ifdef HAVE_MLOCK
             munlock(map, mapsize);
+#endif
             munmap(map, mapsize);
         }
         else
-- 
2.19.1


From 070bfcfe30f6ae94449bf2ab12cf3a73a13d2595 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <re...@free.fr>
Date: Sun, 24 Feb 2019 02:41:23 +0100
Subject: [PATCH 2/3] use libnetwork on Haiku

---
 cmake/ucommon.cmake | 4 ++++
 configure.ac        | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/cmake/ucommon.cmake b/cmake/ucommon.cmake
index 134c115c..f921f17a 100644
--- a/cmake/ucommon.cmake
+++ b/cmake/ucommon.cmake
@@ -17,6 +17,10 @@ if (NOT UCOMMON_CONFIGURED)
         set(UCOMMON_LIBS ${UCOMMON_LIBS} nsl socket)
     endif()
 
+    if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
+        set(UCOMMON_LIBS ${UCOMMON_LIBS} network)
+    endif()
+
     if(CMAKE_COMPILER_IS_GNUCXX)
         set(UCOMMON_VISIBILITY_FLAG "-fvisibility=hidden")
         if(MINGW OR MSYS OR CMAKE_SYSTEM MATCHES "Windows")
diff --git a/configure.ac b/configure.ac
index 77bc9265..455c31fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,9 @@ osf*|cygwin*|mingw*)
 darwin*)
     MODULE_FLAGS="-dynamic -bundle -undefined suppress -flat_namespace 
-read_only_relocs suppress"
     ;;
+haiku*)
+    UCOMMON_LIBC="-lnetwork"
+    ;;
 esac
 
 AC_ARG_ENABLE(posix-timers,
-- 
2.19.1


From d8c6e7fc8a2f5a2caecf78e3fc1c56debdb3fd73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <re...@free.fr>
Date: Sun, 24 Feb 2019 02:41:45 +0100
Subject: [PATCH 3/3] use ifr_name (Haiku doesn't have named unions in ifreq)

---
 corelib/socket.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/corelib/socket.cpp b/corelib/socket.cpp
index 077fe930..4db6bf0b 100644
--- a/corelib/socket.cpp
+++ b/corelib/socket.cpp
@@ -3027,7 +3027,7 @@ int Socket::bindto(socket_t so, const char *host, const 
char *svc, int protocol)
     if(host && !strchr(host, '.') && !strchr(host, ':')) {
         struct ifreq ifr;
         memset(&ifr, 0, sizeof(ifr));
-        strncpy(ifr.ifr_ifrn.ifrn_name, host, IFNAMSIZ);
+        strncpy(ifr.ifr_name, host, IFNAMSIZ);
         ifr.ifr_name[IFNAMSIZ - 1] = '\0';
         setsockopt(so, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr));
         host = NULL;
-- 
2.19.1

_______________________________________________
Bug-commoncpp mailing list
Bug-commoncpp@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-commoncpp

Reply via email to