summaryrefslogtreecommitdiff
path: root/src/sysdeps/trysplice.c
blob: 7428418b9095a3b972a98c4fef4e17fee1330c43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* 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)
{
  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 ;
  }
  return 0 ;
}