This allows to split single write_blocked(buf, 123) call into multiple calls write_blocked(buf, 100, 1); write_blocked(buf, 23, 1); write_blocked(buf, 0, 0); No call sites do this yet though. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- archive-tar.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/archive-tar.c b/archive-tar.c index 3be0cdf..9060f9a 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -30,7 +30,7 @@ static void write_if_needed(void) * queues up writes, so that all our write(2) calls write exactly one * full block; pads writes to RECORDSIZE */ -static void write_blocked(const void *data, unsigned long size) +static void write_blocked(const void *data, unsigned long size, int partial) { const char *buf = data; unsigned long tail; @@ -54,6 +54,8 @@ static void write_blocked(const void *data, unsigned long size) memcpy(block + offset, buf, size); offset += size; } + if (partial) + return; tail = offset % RECORDSIZE; if (tail) { memset(block + offset, 0, RECORDSIZE - tail); @@ -155,8 +157,8 @@ static int write_extended_header(struct archiver_args *args, mode = 0100666; sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1)); prepare_header(args, &header, mode, size); - write_blocked(&header, sizeof(header)); - write_blocked(buffer, size); + write_blocked(&header, sizeof(header), 0); + write_blocked(buffer, size, 0); return 0; } @@ -234,9 +236,9 @@ static int write_tar_entry(struct archiver_args *args, } } strbuf_release(&ext_header); - write_blocked(&header, sizeof(header)); + write_blocked(&header, sizeof(header), 0); if (S_ISREG(mode) && buffer && size > 0) - write_blocked(buffer, size); + write_blocked(buffer, size, 0); free(buffer); return err; } @@ -255,8 +257,8 @@ static int write_global_extended_header(struct archiver_args *args) mode = 0100666; strcpy(header.name, "pax_global_header"); prepare_header(args, &header, mode, ext_header.len); - write_blocked(&header, sizeof(header)); - write_blocked(ext_header.buf, ext_header.len); + write_blocked(&header, sizeof(header), 0); + write_blocked(ext_header.buf, ext_header.len, 0); strbuf_release(&ext_header); return err; } -- 1.7.8.36.g69ee2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html