sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

concat.c (398B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <unistd.h>
      3 
      4 #include "../util.h"
      5 
      6 int
      7 concat(int f1, const char *s1, int f2, const char *s2)
      8 {
      9 	char buf[BUFSIZ];
     10 	ssize_t n;
     11 
     12 	while ((n = read(f1, buf, sizeof(buf))) > 0) {
     13 		if (writeall(f2, buf, n) < 0) {
     14 			weprintf("write %s:", s2);
     15 			return -2;
     16 		}
     17 	}
     18 	if (n < 0) {
     19 		weprintf("read %s:", s1);
     20 		return -1;
     21 	}
     22 	return 0;
     23 }