diff options
Diffstat (limited to 'lib/tar')
-rw-r--r-- | lib/tar/Makemodule.am | 2 | ||||
-rw-r--r-- | lib/tar/padd_file.c | 40 | ||||
-rw-r--r-- | lib/tar/write_header.c | 4 |
3 files changed, 43 insertions, 3 deletions
diff --git a/lib/tar/Makemodule.am b/lib/tar/Makemodule.am index 42f11ae..129d66f 100644 --- a/lib/tar/Makemodule.am +++ b/lib/tar/Makemodule.am @@ -2,7 +2,7 @@ libtar_a_SOURCES = lib/tar/read_header.c lib/tar/write_header.c lib/tar/skip.c libtar_a_SOURCES += lib/tar/number.c lib/tar/checksum.c lib/tar/cleanup.c libtar_a_SOURCES += lib/tar/read_sparse_map.c lib/tar/read_sparse_map_old.c libtar_a_SOURCES += lib/tar/base64.c lib/tar/urldecode.c lib/tar/internal.h -libtar_a_SOURCES += include/tar.h +libtar_a_SOURCES += lib/tar/padd_file.c include/tar.h libtar_a_CFLAGS = $(AM_CFLAGS) libtar_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/tar/padd_file.c b/lib/tar/padd_file.c new file mode 100644 index 0000000..471370d --- /dev/null +++ b/lib/tar/padd_file.c @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * padd_file.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#include "config.h" +#include "tar.h" + +#include <stdlib.h> +#include <stdio.h> + +int padd_file(int outfd, sqfs_u64 size) +{ + size_t padd_sz = size % TAR_RECORD_SIZE; + int status = -1; + sqfs_u8 *buffer; + + if (padd_sz == 0) + return 0; + + padd_sz = TAR_RECORD_SIZE - padd_sz; + + buffer = calloc(1, padd_sz); + if (buffer == NULL) + goto fail_errno; + + if (write_data("padding output file to block size", + outfd, buffer, padd_sz)) { + goto out; + } + + status = 0; +out: + free(buffer); + return status; +fail_errno: + perror("padding output file to block size"); + goto out; +} diff --git a/lib/tar/write_header.c b/lib/tar/write_header.c index 4c8caa2..14802c0 100644 --- a/lib/tar/write_header.c +++ b/lib/tar/write_header.c @@ -109,7 +109,7 @@ static int write_gnu_header(int fd, const struct stat *orig, return -1; } - return padd_file(fd, payload_len, 512); + return padd_file(fd, payload_len); } static size_t num_digits(size_t num) @@ -152,7 +152,7 @@ static int write_schily_xattr(int fd, const struct stat *orig, dprintf(fd, "%zu %s%s=%s\n", len, prefix, it->key, it->value); } - return padd_file(fd, total_size, 512); + return padd_file(fd, total_size); } int write_tar_header(int fd, const struct stat *sb, const char *name, |