2011-05-26 17:18:42 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2017-07-03 21:58:49 +00:00
|
|
|
#include <unistd.h>
|
2013-03-05 20:46:48 +00:00
|
|
|
|
2011-05-26 17:18:42 +00:00
|
|
|
#include "../util.h"
|
|
|
|
|
2017-07-03 21:58:49 +00:00
|
|
|
int
|
|
|
|
concat(int f1, const char *s1, int f2, const char *s2)
|
2011-05-26 17:18:42 +00:00
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
2017-07-03 21:58:49 +00:00
|
|
|
ssize_t n;
|
2011-05-26 17:18:42 +00:00
|
|
|
|
2017-07-03 21:58:49 +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;
|
2013-03-05 20:46:48 +00:00
|
|
|
}
|
2017-07-03 21:58:49 +00:00
|
|
|
return 0;
|
2011-05-26 17:18:42 +00:00
|
|
|
}
|