summaryrefslogtreecommitdiff
path: root/lib/tar/read_retry.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 23:20:35 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-04-17 23:31:32 +0200
commit1fe3f86230a970b3974f16a6bc2e819fdaf55b58 (patch)
tree7f9f097840a68e0e6605059c9ebb2f8ee2d3fbfd /lib/tar/read_retry.c
parent15250710c63a2c3d230304e46a03532f787759fb (diff)
Cleanup: split read_header.c in libtar.a
Simply moving the pax header decoding to a separate file and splitting out the common helper functions should be a good start. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
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;
+}