From 9c273d5ca1810da8cf03a2af78b3fa5cbaaf2df7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 18 Dec 2012 17:21:14 +0100 Subject: s3-lib: Cleanup transfer_file_internal() a bit. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andreas Schneider Reviewed-by: Günther Deschner --- source3/lib/util_transfer_file.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_transfer_file.c b/source3/lib/util_transfer_file.c index 37a7d6e248..00a2c9d9de 100644 --- a/source3/lib/util_transfer_file.c +++ b/source3/lib/util_transfer_file.c @@ -45,11 +45,15 @@ ssize_t transfer_file_internal(void *in_file, size_t num_to_read_thistime; size_t num_written = 0; + if (n == 0) { + return 0; + } + if ((buf = SMB_MALLOC_ARRAY(char, TRANSFER_BUF_SIZE)) == NULL) { return -1; } - while (total < n) { + do { num_to_read_thistime = MIN((n - total), TRANSFER_BUF_SIZE); read_ret = (*read_fn)(in_file, buf, num_to_read_thistime); @@ -84,7 +88,7 @@ ssize_t transfer_file_internal(void *in_file, } total += (size_t)read_ret; - } + } while (total < n); SAFE_FREE(buf); return (ssize_t)total; -- cgit