sbase/libutil/concat.c

24 lines
398 B
C
Raw Normal View History

2011-05-26 17:18:42 +00:00
/* See LICENSE file for copyright and license details. */
#include <unistd.h>
2011-05-26 17:18:42 +00:00
#include "../util.h"
int
concat(int f1, const char *s1, int f2, const char *s2)
2011-05-26 17:18:42 +00:00
{
char buf[BUFSIZ];
ssize_t n;
2011-05-26 17:18:42 +00:00
while ((n = read(f1, buf, sizeof(buf))) > 0) {
if (writeall(f2, buf, n) < 0) {
weprintf("write %s:", s2);
return -2;
}
}
if (n < 0) {
weprintf("read %s:", s1);
return -1;
}
return 0;
2011-05-26 17:18:42 +00:00
}