aboutsummaryrefslogtreecommitdiff
path: root/lib/tar/read_retry.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tar/read_retry.c')
-rw-r--r--lib/tar/read_retry.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/tar/read_retry.c b/lib/tar/read_retry.c
index c76e5e5..2a2f82c 100644
--- a/lib/tar/read_retry.c
+++ b/lib/tar/read_retry.c
@@ -6,10 +6,8 @@
*/
#include "config.h"
-#include <errno.h>
-#include <stdio.h>
-
#include "tar.h"
+#include "internal.h"
int read_retry(const char *errstr, FILE *fp, void *buffer, size_t size)
{
@@ -34,3 +32,26 @@ int read_retry(const char *errstr, FILE *fp, void *buffer, size_t size)
return 0;
}
+
+char *record_to_memory(FILE *fp, sqfs_u64 size)
+{
+ char *buffer = malloc(size + 1);
+
+ if (buffer == NULL)
+ goto fail_errno;
+
+ if (read_retry("reading tar record", fp, buffer, size))
+ 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;
+}