0cdd1ca2869b5b91697f569d8686bf15820a2a99
[splice.git] / splice.h
1 #ifndef SPLICE_H
2 #define SPLICE_H
3
4 #if defined(__i386__)
5 #define __NR_splice     313
6 #define __NR_tee        315
7 #elif defined(__x86_64__)
8 #define __NR_splice     275
9 #define __NR_tee        276
10 #elif defined(__powerpc__) || defined(__powerpc64__)
11 #define __NR_splice     283
12 #define __NR_tee        284
13 #elif defined(__ia64__)
14 #define __NR_splice     1297
15 #define __NR_tee        1301
16 #else
17 #error unsupported arch
18 #endif
19
20 #define SPLICE_F_MOVE   (0x01)  /* move pages instead of copying */
21 #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
22                                  /* we may still block on the fd we splice */
23                                  /* from/to, of course */
24 #define SPLICE_F_MORE   (0x04)  /* expect more data */
25
26 static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
27                          size_t len, unsigned long flags)
28 {
29         return syscall(__NR_splice, fdin, off_in, fdout, off_out, len, flags);
30
31 }
32
33 static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
34 {
35         return syscall(__NR_tee, fdin, fdout, len, flags);
36 }
37
38 #define SPLICE_SIZE     (64*1024)
39
40 #define BUG_ON(c) assert(!(c))
41
42 #define min(x,y) ({ \
43         typeof(x) _x = (x);     \
44         typeof(y) _y = (y);     \
45         (void) (&_x == &_y);            \
46         _x < _y ? _x : _y; })
47
48 #define max(x,y) ({ \
49         typeof(x) _x = (x);     \
50         typeof(y) _y = (y);     \
51         (void) (&_x == &_y);            \
52         _x > _y ? _x : _y; })
53
54 static inline int error(const char *n)
55 {
56         perror(n);
57         return -1;
58 }
59
60 #endif