summaryrefslogtreecommitdiff
path: root/src/sysdeps/trysplice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysdeps/trysplice.c')
-rw-r--r--src/sysdeps/trysplice.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/sysdeps/trysplice.c b/src/sysdeps/trysplice.c
index 8e8bd72..969c5ea 100644
--- a/src/sysdeps/trysplice.c
+++ b/src/sysdeps/trysplice.c
@@ -1,29 +1,22 @@
/* ISC license. */
+#undef _POSIX_C_SOURCE
+#undef _XOPEN_SOURCE
+
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
-#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
-
-#define N 4096
+#include <sys/uio.h>
int main (void)
{
- int p[2] ;
- int fd ;
- if (pipe(p) < 0) return 111 ;
- fd = open("./src/sysdeps/trysplice.c", O_RDONLY) ;
- if (fd < 0) return 111 ;
-
- for (;;)
- {
- ssize_t r = splice(fd, 0, p[1], 0, N, 0) ;
- if (r < 0) return 1 ;
- if (!r) break ;
- if (splice(p[0], 0, 1, 0, r, 0) < r) return 2 ;
- }
+ char s[2][2] ;
+ struct iovec v[2] = { { .iov_base = s[0], .iov_len = 2 }, { .iov_base = s[1], .iov_len = 2 } } ;
+ loff_t in, out ;
+ ssize_t r = splice(0, &in, 1, &out, 4096, SPLICE_F_MOVE) ;
+ r = tee(0, 1, 4096, SPLICE_F_NONBLOCK) ;
+ r = vmsplice(0, v, 2, 0) ;
return 0 ;
}