[PATCH] vmsplice2: warning fix
[splice.git] / splice.h
CommitLineData
d8525fbd
JA
1#ifndef SPLICE_H
2#define SPLICE_H
3
a05d2973 4#include <errno.h>
001a41ec 5#include <sys/uio.h>
76797253 6#include <sys/stat.h>
a05d2973 7#include <asm/unistd.h>
001a41ec 8
d8525fbd 9#if defined(__i386__)
a05d2973
JA
10#define __NR_sys_splice 313
11#define __NR_sys_tee 315
12#define __NR_sys_vmsplice 316
d8525fbd 13#elif defined(__x86_64__)
a05d2973
JA
14#define __NR_sys_splice 275
15#define __NR_sys_tee 276
16#define __NR_sys_vmsplice 278
d8525fbd 17#elif defined(__powerpc__) || defined(__powerpc64__)
a05d2973
JA
18#define __NR_sys_splice 283
19#define __NR_sys_tee 284
20#define __NR_sys_vmsplice 285
d8525fbd 21#elif defined(__ia64__)
a05d2973
JA
22#define __NR_sys_splice 1297
23#define __NR_sys_tee 1301
24#define __NR_sys_vmsplice 1302
d8525fbd
JA
25#else
26#error unsupported arch
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 */
96897528 34#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
d8525fbd 35
a05d2973
JA
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);
39
d8525fbd
JA
40static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
41 size_t len, unsigned long flags)
42{
a05d2973 43 return sys_splice(fdin, off_in, fdout, off_out, len, flags);
d8525fbd
JA
44}
45
46static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
47{
a05d2973 48 return sys_tee(fdin, fdout, len, flags);
d8525fbd
JA
49}
50
001a41ec
JA
51static inline int vmsplice(int fd, const struct iovec *iov,
52 unsigned long nr_segs, unsigned int flags)
7ee0f27f 53{
a05d2973 54 return sys_vmsplice(fd, iov, nr_segs, flags);
7ee0f27f
JA
55}
56
d8525fbd
JA
57#define SPLICE_SIZE (64*1024)
58
59#define BUG_ON(c) assert(!(c))
60
61#define min(x,y) ({ \
62 typeof(x) _x = (x); \
63 typeof(y) _y = (y); \
64 (void) (&_x == &_y); \
65 _x < _y ? _x : _y; })
66
67#define max(x,y) ({ \
68 typeof(x) _x = (x); \
69 typeof(y) _y = (y); \
70 (void) (&_x == &_y); \
71 _x > _y ? _x : _y; })
72
73static inline int error(const char *n)
74{
75 perror(n);
76 return -1;
77}
78
76797253
JA
79static int __check_pipe(int pfd)
80{
81 struct stat sb;
82
83 if (fstat(pfd, &sb) < 0)
84 return error("stat");
85 if (!S_ISFIFO(sb.st_mode))
86 return 1;
87
88 return 0;
89}
90
91static inline int check_input_pipe(void)
92{
93 if (!__check_pipe(STDIN_FILENO))
94 return 0;
95
96 fprintf(stderr, "stdin must be a pipe\n");
97 return 1;
98}
99
100static inline int check_output_pipe(void)
101{
102 if (!__check_pipe(STDOUT_FILENO))
103 return 0;
104
105 fprintf(stderr, "stdout must be a pipe\n");
106 return 1;
107}
108
d8525fbd 109#endif