fd_cat.c (382B)
1 /* ISC license. */ 2 3 #include <unistd.h> 4 5 #include <skalibs/allreadwrite.h> 6 #include <skalibs/djbunix.h> 7 8 #define BSIZE 65536 9 10 off_t fd_cat (int from, int to) 11 { 12 off_t n = 0 ; 13 char buf[BSIZE] ; 14 for (;;) 15 { 16 ssize_t r = fd_read(from, buf, BSIZE) ; 17 if (r == -1) return -1 ; 18 if (!r) break ; 19 if (allwrite(to, buf, r) < r) return -1 ; 20 n += r ; 21 } 22 return n ; 23 }