Re: Emulation of sendfile().
On 26/10/2013 17:49, Mats Erik Andersson wrote:
> lördag den 26 oktober 2013 klockan 17:16 skrev Robert Millan detta:
>>
>> Which sendfile() do you want?
>>
>> There's the SYS_sendfile syscall, which is defined as bsd_sendfile() in
>> <bits/socket.h> but awkwardly not exported in Versions.
>
> I will have a go with this in due time. Presumably it exposes the
> same signature as sendfile(3) of FreeBSD.
Please could you try:
1. Rebuild freebsd-glue with attached patch
2. Add "-I /usr/include/freebsd" to CFLAGS in your package.
3. Add "-lfreebsd-glue" to LDFLAGS in your package.
?
This should seamlessly map sendfile() to the BSD version.
Alternatively, you can skip step 2 and use bsd_sendfile() instead.
--
Robert Millan
Index: include/sys/socket.h
===================================================================
--- include/sys/socket.h (revision 5077)
+++ include/sys/socket.h (working copy)
@@ -9,4 +9,10 @@
int setfib(int fib);
__END_DECLS
+#ifdef __FreeBSD_kernel__
+/* bsd_sendfile prototype already in glibc. */
+#define sendfile(fd, s, offset, nbytes, hdtr, sbytes, flags) \
+ bsd_sendfile((fd), (s), (offset), (nbytes), (hdtr), (sbytes), (flags))
#endif
+
+#endif
Index: src/sendfile.c
===================================================================
--- src/sendfile.c (revision 0)
+++ src/sendfile.c (revision 0)
@@ -0,0 +1,12 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+
+int
+bsd_sendfile (int fd, int s, off_t offset, size_t nbytes,
+ struct sf_hdtr *hdtr, off_t *sbytes, int flags)
+{
+ return syscall (SYS_sendfile, fd, s, offset, nbytes, hdtr, sbytes, flags);
+}
Index: src/Makefile
===================================================================
--- src/Makefile (revision 5079)
+++ src/Makefile (working copy)
@@ -24,6 +24,7 @@
disklabel.c \
linkaddr.c \
login_class.c \
+ sendfile.c \
socket.c \
${NULL}
.endif
Reply to: