#! /bin/sh /usr/share/dpatch/dpatch-run
## 029_fix_kfreebsd.dpatch by  <root@debian-kfbsd-amd64>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Fix build on kfreebsd

@DPATCH@

Description: fix kfreebsd
 This patch fixes the build on kfreebsd by tweaking some
 ifdefs.

 in wavy_edge.h we treat kfreebsd like other BSDs since
 kqueue and epoll are kernel features.

 in mod_replace_stream.cc we treat all glibc based systems
 like linux as sendfile is a libc feature.

Author: Peter Michael Green <plugwash@p10link.net>
Bug-Debian: http://bugs.debian.org/665489

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- kumofs-0.4.13.orig/src/mpsrc/wavy_edge.h
+++ kumofs-0.4.13/src/mpsrc/wavy_edge.h
@@ -15,7 +15,7 @@
 #      define MP_WAVY_EDGE epoll
 #    elif defined(__APPLE__) && defined(__MACH__)
 #      define MP_WAVY_EDGE kqueue
-#    elif defined(__FreeBSD__) || defined(__NetBSD__)
+#    elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__FreeBSD_kernel__)
 #      define MP_WAVY_EDGE kqueue
 #    elif defined(__sun__)
 #      define MP_WAVY_EDGE eventport
--- kumofs-0.4.13.orig/src/logic/server/mod_replace_stream.cc
+++ kumofs-0.4.13/src/logic/server/mod_replace_stream.cc
@@ -24,7 +24,7 @@
 #include <fcntl.h>
 #include <algorithm>
 
-#if defined(__linux__) || defined(__sun__)
+#if defined(__linux__) || defined(__sun__) || defined(__GLIBC__)
 #include <sys/sendfile.h>
 #endif
 
@@ -287,7 +287,7 @@ void mod_replace_stream_t::stream_accumu
 	m_mmap_stream->flush();
 	size_t size = m_mmap_stream->size();
 	//m_mmap_stream.reset(NULL);  // FIXME needed?
-#if defined(__linux__) || defined(__sun__)
+#if defined(__linux__) || defined(__sun__) || defined(__GLIBC__)
 	while(size > 0) {
 		ssize_t rl = ::sendfile(sock, m_fd.get(), NULL, size);
 		if(rl <= 0) { throw mp::system_error(errno, "offer send error"); }
