diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2014-09-18 18:55:44 +0000 |
commit | 3534b428629be185e096be99e3bd5fdfe32d5544 (patch) | |
tree | 210ef3198ed66bc7f7b7bf6a85e4579f455e5a36 /src/sysdeps/trysplice.c | |
download | skalibs-3534b428629be185e096be99e3bd5fdfe32d5544.tar.xz |
initial commit with rc for skalibs-2.0.0.0
Diffstat (limited to 'src/sysdeps/trysplice.c')
-rw-r--r-- | src/sysdeps/trysplice.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/sysdeps/trysplice.c b/src/sysdeps/trysplice.c new file mode 100644 index 0000000..6b566b8 --- /dev/null +++ b/src/sysdeps/trysplice.c @@ -0,0 +1,28 @@ +/* ISC license. */ + +#define _GNU_SOURCE +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#define N 4096 + +int main (void) +{ + char buf[N] ; + 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 (;;) + { + register int 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 ; + } + return 0 ; +} |