[PATCH] splice-bench: really fix warning
[splice.git] / splice-in.c
CommitLineData
d8525fbd
JA
1/*
2 * Splice argument file to stdout
3 */
4#include <stdio.h>
5#include <stdlib.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10
11#include "splice.h"
12
13int main(int argc, char *argv[])
14{
15 struct stat sb;
16 int fd;
17
18 if (argc < 2) {
19 printf("%s: infile\n", argv[0]);
20 return 1;
21 }
22
23 fd = open(argv[1], O_RDONLY);
49b68ef7
JA
24 if (fd < 0)
25 return error("open input");
d8525fbd 26
49b68ef7
JA
27 if (fstat(fd, &sb) < 0)
28 return error("stat input");
d8525fbd
JA
29
30 do {
31 int ret = splice(fd, NULL, STDOUT_FILENO, NULL, sb.st_size, 0);
32
49b68ef7
JA
33 if (ret < 0)
34 return error("splice");
35 else if (!ret)
d8525fbd
JA
36 break;
37
38 sb.st_size -= ret;
39 } while (1);
40
41 close(fd);
42 return 0;
43}