CC = gcc
-CFLAGS = -Wall -O2 -g
-ALL_CFLAGS = $(CFLAGS) -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
+CFLAGS = -Wall -O2 -g -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
PROGS = ktee splice-cp splice-in splice-out splice-net splice-test4c splice-test4s
all: depend $(PROGS)
%.o: %.c
- $(CC) -o $*.o -c $(ALL_CFLAGS) $<
+ $(CC) -o $*.o -c $(CFLAGS) $<
depend:
- @$(CC) -MM $(ALL_CFLAGS) *.c 1> .depend
+ @$(CC) -MM $(CFLAGS) *.c 1> .depend
clean:
-rm -f *.o $(PROGS) .depend
}
in_fd = open(argv[1], O_RDONLY);
- if (in_fd < 0) {
- perror("open in");
- return 1;
- }
+ if (in_fd < 0)
+ return error("open input");
- if (fstat(in_fd, &sb) < 0) {
- perror("stat");
- return 1;
- }
+ if (fstat(in_fd, &sb) < 0)
+ return error("stat input");
out_fd = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (out_fd < 0) {
- perror("open out");
- return 1;
- }
+ if (out_fd < 0)
+ return error("open output");
- if (pipe(pfds) < 0) {
- perror("pipe");
- return 1;
- }
+ if (pipe(pfds) < 0)
+ return error("pipe");
do {
- int this_len = min(BS, sb.st_size);
+ int this_len = min((off_t) BS, sb.st_size);
int ret = splice(in_fd, NULL, pfds[1], NULL, this_len, SPLICE_F_NONBLOCK);
if (ret <= 0)
}
fd = open(argv[1], O_RDONLY);
- if (fd < 0) {
- perror("open");
- return 1;
- }
+ if (fd < 0)
+ return error("open input");
- if (fstat(fd, &sb) < 0) {
- perror("stat");
- return 1;
- }
+ if (fstat(fd, &sb) < 0)
+ return error("stat input");
do {
int ret = splice(fd, NULL, STDOUT_FILENO, NULL, sb.st_size, 0);
- if (ret < 0) {
- perror("splice");
- break;
- } else if (!ret)
+ if (ret < 0)
+ return error("splice");
+ else if (!ret)
break;
sb.st_size -= ret;
if (inet_aton(argv[2], &addr.sin_addr) != 1) {
struct hostent *hent = gethostbyname(argv[2]);
- if (!hent) {
- perror("gethostbyname");
- return 1;
- }
+ if (!hent)
+ return error("gethostbyname");
memcpy(&addr.sin_addr, hent->h_addr, 4);
}
printf("Connecting to %s/%d\n", argv[2], port);
fd = socket(AF_INET, SOCK_STREAM, 0);
- if (fd < 0) {
- perror("socket");
- return 1;
- }
+ if (fd < 0)
+ return error("socket");
- if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- perror("connect");
- return 1;
- }
+ if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0)
+ return error("connect");
- if (pipe(pfd) < 0) {
- perror("pipe");
- return 1;
- }
+ if (pipe(pfd) < 0)
+ return error("pipe");
ffd = open(argv[1], O_RDWR);
- if (ffd < 0) {
- perror("open input");
- return 1;
- }
+ if (ffd < 0)
+ return error("open input");
signal(SIGINT, show_rate);
gettimeofday(&start_time, NULL);
if (!bla)
printf("spliced %d\n", ret);
- if (ret < 0) {
- perror("splice");
- break;
- } else if (!ret) {
+ if (ret < 0)
+ return error("splice");
+ else if (!ret) {
break;
}
b_sent += ret;
while (ret > 0) {
int flags = 0;
int written = splice(pfd[0], NULL, fd, NULL, ret, flags);
- if (written < 0) {
- perror("splice-out");
- break;
- } else if (!written)
+ if (written < 0)
+ return error("splice-out");
+ else if (!written)
break;
ret -= written;
}
}
fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
- if (fd < 0) {
- perror("open");
- return 1;
- }
+ if (fd < 0)
+ return error("open");
do {
int ret = splice(STDIN_FILENO, NULL, fd, NULL, SPLICE_SIZE, 0);
- if (ret < 0) {
- perror("splice");
- break;
- } else if (!ret)
+ if (ret < 0)
+ return error("splice");
+ else if (!ret)
break;
} while (1);