diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-07 14:44:17 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-10-07 14:46:40 +0200 |
commit | 267d5318e1cbf69a071b5188dda50310af2f2f8b (patch) | |
tree | 9b17035763ab4c69458f28fe37258713c45920a5 /lib/tar/padd_file.c | |
parent | 3a7d758d1d5a9b6499bdc3f75077932ba66f89d7 (diff) |
Cleanup: Move padd_file function to libtar
It's only ever used for padding tarballs.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/padd_file.c')
-rw-r--r-- | lib/tar/padd_file.c | 40 |
1 files changed, 40 insertions, 0 deletions
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; +} |