7 #include <asm/unistd.h>
10 #define __NR_sys_splice 313
11 #define __NR_sys_tee 315
12 #define __NR_sys_vmsplice 316
13 #elif defined(__x86_64__)
14 #define __NR_sys_splice 275
15 #define __NR_sys_tee 276
16 #define __NR_sys_vmsplice 278
17 #elif defined(__powerpc__) || defined(__powerpc64__)
18 #define __NR_sys_splice 283
19 #define __NR_sys_tee 284
20 #define __NR_sys_vmsplice 285
21 #elif defined(__ia64__)
22 #define __NR_sys_splice 1297
23 #define __NR_sys_tee 1301
24 #define __NR_sys_vmsplice 1302
26 #error unsupported arch
29 #define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
30 #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
31 /* we may still block on the fd we splice */
32 /* from/to, of course */
33 #define SPLICE_F_MORE (0x04) /* expect more data */
34 #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
36 _syscall6(int, sys_splice, int, fdin, loff_t *, off_in, int, fdout, loff_t *, off_out, size_t, len, unsigned int, flags);
37 _syscall4(int, sys_vmsplice, int, fd, const struct iovec *, iov, unsigned long, nr_segs, unsigned int, flags);
38 _syscall4(int, sys_tee, int, fdin, int, fdout, size_t, len, unsigned int, flags);
40 static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
41 size_t len, unsigned long flags)
43 return sys_splice(fdin, off_in, fdout, off_out, len, flags);
46 static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
48 return sys_tee(fdin, fdout, len, flags);
51 static inline int vmsplice(int fd, const struct iovec *iov,
52 unsigned long nr_segs, unsigned int flags)
54 return sys_vmsplice(fd, iov, nr_segs, flags);
57 #define SPLICE_SIZE (64*1024)
59 #define BUG_ON(c) assert(!(c))
64 (void) (&_x == &_y); \
70 (void) (&_x == &_y); \
73 static inline int error(const char *n)
79 static int __check_pipe(int pfd)
83 if (fstat(pfd, &sb) < 0)
85 if (!S_ISFIFO(sb.st_mode))
91 static inline int check_input_pipe(void)
93 if (!__check_pipe(STDIN_FILENO))
96 fprintf(stderr, "stdin must be a pipe\n");
100 static inline int check_output_pipe(void)
102 if (!__check_pipe(STDOUT_FILENO))
105 fprintf(stderr, "stdout must be a pipe\n");