blob: ba422de81d0a5a7851706fa99ebea0984f319354 (
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
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
* record_to_memory.c
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
#include "config.h"
#include "tar/tar.h"
#include "internal.h"
#include <stdlib.h>
char *record_to_memory(istream_t *fp, size_t size)
{
char *buffer = malloc(size + 1);
int ret;
if (buffer == NULL)
goto fail_errno;
ret = istream_read(fp, buffer, size);
if (ret < 0)
goto fail;
if ((size_t)ret < size) {
fputs("Reading tar record: unexpected end-of-file.\n", stderr);
goto fail;
}
if (skip_padding(fp, size))
goto fail;
buffer[size] = '\0';
return buffer;
fail_errno:
perror("reading tar record");
goto fail;
fail:
free(buffer);
return NULL;
}
|