aboutsummaryrefslogtreecommitdiff
path: root/lib/tar/skip.c
blob: 36cd47034248c47ec5f2e7fd5de3aa52a8a669a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * skip.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "config.h"

#include "tar.h"

#include <stdio.h>

static int skip_bytes(FILE *fp, sqfs_u64 size)
{
	unsigned char buffer[1024];
	size_t diff;

	while (size != 0) {
		diff = sizeof(buffer);
		if (diff > size)
			diff = size;

		if (read_retry("reading tar record padding", fp, buffer, diff))
			return -1;

		size -= diff;
	}

	return 0;
}

int skip_padding(FILE *fp, sqfs_u64 size)
{
	size_t tail = size % 512;

	return tail ? skip_bytes(fp, 512 - tail) : 0;
}

int skip_entry(FILE *fp, sqfs_u64 size)
{
	size_t tail = size % 512;

	return skip_bytes(fp, tail ? (size + 512 - tail) : size);
}