diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 18:22:27 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2019-09-20 18:22:27 +0000 |
commit | 6011d413604df8224b91ca9f9b3d50663b60e117 (patch) | |
tree | ca36404ebcc87922d26664dd93e2c0ebd23bef67 /src/sysdeps/trysplice.c | |
parent | 98d3a523be4fff36f65e71c37df8b9e127b12b83 (diff) | |
download | skalibs-6011d413604df8224b91ca9f9b3d50663b60e117.tar.xz |
sysdeps redesign: first part: minimize clr tests
Remaining clr:
emptyregex: can be safely guessed to no
nullispointer: can't be safely guessed, but do we need the test?
devurandom: can't be safely guessed
malloc0: can more or less be safely guessed to no
Diffstat (limited to 'src/sysdeps/trysplice.c')
-rw-r--r-- | src/sysdeps/trysplice.c | 27 |
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 ; } |