commit 91aed23a5d5032b4a820a10bd3ddd6dd3968eefa Author: Roberto E. Vargas Caballero <k...@shike2.com> AuthorDate: Fri Mar 22 04:32:56 2024 +0100 Commit: Roberto E. Vargas Caballero <k...@shike2.com> CommitDate: Thu Dec 19 13:30:32 2024 +0100
Move more things around diff --git a/ubase/libutil/concat.c b/ubase/libutil/concat.c index ef1e5b9..2e9aa52 100644 --- a/ubase/libutil/concat.c +++ b/ubase/libutil/concat.c @@ -1,21 +1,23 @@ /* See LICENSE file for copyright and license details. */ -#include <stdio.h> +#include <unistd.h> -#include "../text.h" #include "../util.h" -void -concat(FILE *fp1, const char *s1, FILE *fp2, const char *s2) +int +concat(int f1, const char *s1, int f2, const char *s2) { char buf[BUFSIZ]; - size_t n; + ssize_t n; - while ((n = fread(buf, 1, sizeof(buf), fp1)) > 0) { - if (fwrite(buf, 1, n, fp2) != n) - eprintf("%s: write error:", s2); - if (feof(fp1)) - break; + while ((n = read(f1, buf, sizeof(buf))) > 0) { + if (writeall(f2, buf, n) < 0) { + weprintf("write %s:", s2); + return -2; + } } - if (ferror(fp1)) - eprintf("%s: read error:", s1); + if (n < 0) { + weprintf("read %s:", s1); + return -1; + } + return 0; }