From 9033453c1849df49d2be39bca92c5b7cdb3234e3 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 12 Nov 2005 11:04:11 +0000 Subject: [PATCH] My last change to this file broke tar x. Sigh. (Trying to make sure we work on file sizes between 2 and 4 gigs on 32 bit machines. For supporting >4 gigs, just use a 64 bit machine already...) --- libbb/copyfd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libbb/copyfd.c b/libbb/copyfd.c index c1962e3c6..0b850884b 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c @@ -29,11 +29,13 @@ static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size) RESERVE_CONFIG_BUFFER(buffer,BUFSIZ); if (src_fd < 0) goto out; - while (!size || total < size) { - ssize_t wrote, xread = (size && size < BUFSIZ) ? size : BUFSIZ; - xread = safe_read(src_fd, buffer, xread); + ssize_t wrote, xread; + + xread = safe_read(src_fd, buffer, + (!size || size - total > BUFSIZ) ? BUFSIZ : size - total); + if (xread > 0) { /* A -1 dst_fd means we need to fake it... */ wrote = (dst_fd < 0) ? xread : bb_full_write(dst_fd, buffer, xread); @@ -42,7 +44,6 @@ static ssize_t bb_full_fd_action(int src_fd, int dst_fd, size_t size) break; } total += wrote; - size -= wrote; } else if (xread < 0) { bb_perror_msg(bb_msg_read_error); break; -- 2.25.1