diff options
Diffstat (limited to 'util/sbase/libutil/concat.c')
-rw-r--r-- | util/sbase/libutil/concat.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/util/sbase/libutil/concat.c b/util/sbase/libutil/concat.c new file mode 100644 index 00000000..2e9aa521 --- /dev/null +++ b/util/sbase/libutil/concat.c @@ -0,0 +1,23 @@ +/* See LICENSE file for copyright and license details. */ +#include <unistd.h> + +#include "../util.h" + +int +concat(int f1, const char *s1, int f2, const char *s2) +{ + char buf[BUFSIZ]; + ssize_t n; + + 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; +} |