[PATCH] vmsplice: add clear option (-c)
[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 #define __NR_vmsplice   316
8 #elif defined(__x86_64__)
9 #define __NR_splice     275
10 #define __NR_tee        276
11 #define __NR_vmsplice   278
12 #elif defined(__powerpc__) || defined(__powerpc64__)
13 #define __NR_splice     283
14 #define __NR_tee        284
15 #define __NR_vmsplice   285
16 #elif defined(__ia64__)
17 #define __NR_splice     1297
18 #define __NR_tee        1301
19 #define __NR_vmsplice   1301
20 #else
21 #error unsupported arch
22 #endif
23
24 #ifndef F_SETPSZ
25 #define F_SETPSZ        15
26 #define F_GETPSZ        16
27 #endif
28
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
35 static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
36                          size_t len, unsigned long flags)
37 {
38         return syscall(__NR_splice, fdin, off_in, fdout, off_out, len, flags);
39
40 }
41
42 static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
43 {
44         return syscall(__NR_tee, fdin, fdout, len, flags);
45 }
46
47 static inline int vmsplice(int fd, void *buffer, size_t len, unsigned int flags)
48 {
49         return syscall(__NR_vmsplice, fd, buffer, len, flags);
50 }
51
52 #define SPLICE_SIZE     (64*1024)
53
54 #define BUG_ON(c) assert(!(c))
55
56 #define min(x,y) ({ \
57         typeof(x) _x = (x);     \
58         typeof(y) _y = (y);     \
59         (void) (&_x == &_y);            \
60         _x < _y ? _x : _y; })
61
62 #define max(x,y) ({ \
63         typeof(x) _x = (x);     \
64         typeof(y) _y = (y);     \
65         (void) (&_x == &_y);            \
66         _x > _y ? _x : _y; })
67
68 static inline int error(const char *n)
69 {
70         perror(n);
71         return -1;
72 }
73
74 #endif