From dfce1186c6034d6f4ea283f5178fd25cbd8f4fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 15 Jun 2022 19:01:14 +0200 Subject: archive-tar: factor out write_block() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All tar archive writes have the same size and are done to the same file descriptor. Move them to a common function, write_block(), to reduce code duplication and make it easy to change the destination. Original-patch-by: Rohit Ashiwal Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- archive-tar.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'archive-tar.c') diff --git a/archive-tar.c b/archive-tar.c index 2717e34a1d..4e6a3deb80 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -38,11 +38,16 @@ static int write_tar_filter_archive(const struct archiver *ar, #define USTAR_MAX_MTIME 077777777777ULL #endif +static void write_block(const void *buf) +{ + write_or_die(1, buf, BLOCKSIZE); +} + /* writes out the whole block, but only if it is full */ static void write_if_needed(void) { if (offset == BLOCKSIZE) { - write_or_die(1, block, BLOCKSIZE); + write_block(block); offset = 0; } } @@ -66,7 +71,7 @@ static void do_write_blocked(const void *data, unsigned long size) write_if_needed(); } while (size >= BLOCKSIZE) { - write_or_die(1, buf, BLOCKSIZE); + write_block(buf); size -= BLOCKSIZE; buf += BLOCKSIZE; } @@ -101,10 +106,10 @@ static void write_trailer(void) { int tail = BLOCKSIZE - offset; memset(block + offset, 0, tail); - write_or_die(1, block, BLOCKSIZE); + write_block(block); if (tail < 2 * RECORDSIZE) { memset(block, 0, offset); - write_or_die(1, block, BLOCKSIZE); + write_block(block); } } -- cgit v1.2.3