archive-tar: factor out write_block()
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 <rohit.ashiwal265@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
96b9e5151b
commit
dfce1186c6
@ -38,11 +38,16 @@ static int write_tar_filter_archive(const struct archiver *ar,
|
|||||||
#define USTAR_MAX_MTIME 077777777777ULL
|
#define USTAR_MAX_MTIME 077777777777ULL
|
||||||
#endif
|
#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 */
|
/* writes out the whole block, but only if it is full */
|
||||||
static void write_if_needed(void)
|
static void write_if_needed(void)
|
||||||
{
|
{
|
||||||
if (offset == BLOCKSIZE) {
|
if (offset == BLOCKSIZE) {
|
||||||
write_or_die(1, block, BLOCKSIZE);
|
write_block(block);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,7 +71,7 @@ static void do_write_blocked(const void *data, unsigned long size)
|
|||||||
write_if_needed();
|
write_if_needed();
|
||||||
}
|
}
|
||||||
while (size >= BLOCKSIZE) {
|
while (size >= BLOCKSIZE) {
|
||||||
write_or_die(1, buf, BLOCKSIZE);
|
write_block(buf);
|
||||||
size -= BLOCKSIZE;
|
size -= BLOCKSIZE;
|
||||||
buf += BLOCKSIZE;
|
buf += BLOCKSIZE;
|
||||||
}
|
}
|
||||||
@ -101,10 +106,10 @@ static void write_trailer(void)
|
|||||||
{
|
{
|
||||||
int tail = BLOCKSIZE - offset;
|
int tail = BLOCKSIZE - offset;
|
||||||
memset(block + offset, 0, tail);
|
memset(block + offset, 0, tail);
|
||||||
write_or_die(1, block, BLOCKSIZE);
|
write_block(block);
|
||||||
if (tail < 2 * RECORDSIZE) {
|
if (tail < 2 * RECORDSIZE) {
|
||||||
memset(block, 0, offset);
|
memset(block, 0, offset);
|
||||||
write_or_die(1, block, BLOCKSIZE);
|
write_block(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user