diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-09-25 19:48:26 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2021-09-25 19:48:26 +0000 |
commit | f268a8871a061395633d943e6f177fa8f8008963 (patch) | |
tree | c01e2ddf63e4934ced4eb34764b520bd47070e08 /src/libstddjb/fd_cat.c | |
parent | 754da814c32de5fbbd8b065e9f106cbb7bfc8ae6 (diff) | |
download | skalibs-f268a8871a061395633d943e6f177fa8f8008963.tar.xz |
Axe iobuffer
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libstddjb/fd_cat.c')
-rw-r--r-- | src/libstddjb/fd_cat.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/libstddjb/fd_cat.c b/src/libstddjb/fd_cat.c index 4acc08a..d9d5c99 100644 --- a/src/libstddjb/fd_cat.c +++ b/src/libstddjb/fd_cat.c @@ -1,27 +1,23 @@ /* ISC license. */ -#include <sys/types.h> +#include <unistd.h> -#include <skalibs/iobuffer.h> +#include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> -int fd_cat (int from, int to) +#define BSIZE 65536 + +off_t fd_cat (int from, int to) { - iobuffer b ; - size_t n = 0 ; - if (!iobuffer_init(&b, from, to)) return -1 ; + off_t n = 0 ; + char buf[BSIZE] ; for (;;) { - ssize_t r = iobuffer_fill(&b) ; - if (r < 0) goto err ; - else if (!r) break ; - if (!iobuffer_flush(&b)) goto err ; + ssize_t r = fd_read(from, buf, BSIZE) ; + if (r == -1) return -1 ; + if (!r) break ; + if (allwrite(to, buf, r) < r) return -1 ; n += r ; } - iobuffer_finish(&b) ; return n ; - - err: - iobuffer_finish(&b) ; - return -1 ; } |