Skip to content

Commit dfce118

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96b9e51 commit dfce118

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

archive-tar.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ static int write_tar_filter_archive(const struct archiver *ar,
3838
#define USTAR_MAX_MTIME 077777777777ULL
3939
#endif
4040

41+
static void write_block(const void *buf)
42+
{
43+
write_or_die(1, buf, BLOCKSIZE);
44+
}
45+
4146
/* writes out the whole block, but only if it is full */
4247
static void write_if_needed(void)
4348
{
4449
if (offset == BLOCKSIZE) {
45-
write_or_die(1, block, BLOCKSIZE);
50+
write_block(block);
4651
offset = 0;
4752
}
4853
}
@@ -66,7 +71,7 @@ static void do_write_blocked(const void *data, unsigned long size)
6671
write_if_needed();
6772
}
6873
while (size >= BLOCKSIZE) {
69-
write_or_die(1, buf, BLOCKSIZE);
74+
write_block(buf);
7075
size -= BLOCKSIZE;
7176
buf += BLOCKSIZE;
7277
}
@@ -101,10 +106,10 @@ static void write_trailer(void)
101106
{
102107
int tail = BLOCKSIZE - offset;
103108
memset(block + offset, 0, tail);
104-
write_or_die(1, block, BLOCKSIZE);
109+
write_block(block);
105110
if (tail < 2 * RECORDSIZE) {
106111
memset(block, 0, offset);
107-
write_or_die(1, block, BLOCKSIZE);
112+
write_block(block);
108113
}
109114
}
110115

0 commit comments

Comments
 (0)