aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

copyall.c (386B)


      1 /* see LICENSE file for copyright and license details */
      2 #include <stdio.h>
      3 #include <unistd.h>
      4 
      5 #include "../util.h"
      6 
      7 /* -1 when reading failed and -2 when writing did, errno says why */
      8 int
      9 copyall(int f1, int f2)
     10 {
     11   char    buf[BUFSIZ];
     12   ssize_t n;
     13 
     14   while ((n = read(f1, buf, sizeof(buf))) > 0) {
     15     if (writeall(f2, buf, n) < 0)
     16       return -2;
     17   }
     18   return n < 0 ? -1 : 0;
     19 }