summaryrefslogtreecommitdiff
path: root/src/libstddjb/iobuffer_kfromu.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2014-09-18 18:55:44 +0000
commit3534b428629be185e096be99e3bd5fdfe32d5544 (patch)
tree210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/libstddjb/iobuffer_kfromu.c
downloadskalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/libstddjb/iobuffer_kfromu.c')
-rw-r--r--src/libstddjb/iobuffer_kfromu.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/libstddjb/iobuffer_kfromu.c b/src/libstddjb/iobuffer_kfromu.c
new file mode 100644
index 0000000..28785e6
--- /dev/null
+++ b/src/libstddjb/iobuffer_kfromu.c
@@ -0,0 +1,41 @@
+/* ISC license. */
+
+#include <skalibs/sysdeps.h>
+
+#ifdef SKALIBS_HASSPLICE
+
+#include <skalibs/nonposix.h>
+#include <fcntl.h>
+#include <sys/uio.h>
+#include <skalibs/buffer.h>
+#include <skalibs/iobuffer.h>
+#include <skalibs/siovec.h>
+
+int iobuffer_kfromu (iobufferk_ref k, iobufferu_ref u)
+{
+ struct iovec iov[2] ;
+ siovec_t v[2] ;
+ int r ;
+ buffer_rpeek(&u->b[0], v) ;
+ iovec_from_siovec(iov, v, 2) ;
+ r = vmsplice(k->p[1], iov, 2, 0) ;
+ if (r < 0) return 0 ;
+ k->n += r ;
+ buffer_rseek(&u->b[0], (unsigned int)r) ;
+ u->b[1].c.p = u->b[0].c.p ;
+ return iobufferu_isempty(u) ;
+}
+
+#else
+
+#include <errno.h>
+#include <skalibs/iobuffer.h>
+
+int iobuffer_kfromu (iobufferk_ref k, iobufferu_ref u)
+{
+ (void)k ;
+ (void)u ;
+ return (errno = ENOSYS, 0) ;
+}
+
+#endif