summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-11-20 15:56:33 -0500
committerJakob Kaivo <jkk@ung.org>2019-11-20 15:56:33 -0500
commitf1cdf4f5ff99255c12347b214853bf68835b6a9c (patch)
tree67d4afb006817a64fe04770af05f59754028eee9
parentad7a406b3d6fa0c14d3b8efc341db4e7b1b297e0 (diff)
read full list of tiles
-rw-r--r--tar.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/tar.c b/tar.c
index f1c61dd..201b455 100644
--- a/tar.c
+++ b/tar.c
@@ -101,13 +101,27 @@ static struct stat tar_header_to_stat(struct tar_header *th)
st.st_gid = pax_atoi(sizeof(th->gid), th->gid, 8);
st.st_size = pax_atoi(sizeof(th->size), th->size, 8);
st.st_mtim.tv_sec = pax_atoi(sizeof(th->mtime), th->mtime, 8);
+ st.st_blocks = st.st_size / 512 + 1;
return st;
}
int tar_list(FILE *input, size_t firstlen, void *firstblock)
{
- struct tar_header *th = firstblock;
- struct stat st = tar_header_to_stat(th);
- pax_list_file(&st, th->name);
+ char zero[512] = {0};
+
+ (void)firstlen;
+ for (;;) {
+ struct tar_header *th = firstblock;
+ struct stat st = tar_header_to_stat(th);
+ pax_list_file(&st, th->name);
+ for (blkcnt_t i = 0; i < st.st_blocks + 1; i++) {
+ if (fread(firstblock, 1, 512, input) != 512) {
+ fprintf(stderr, "pax: error reading input\n");
+ return 1;
+ } else if (memcmp(firstblock, zero, 512) == 0) {
+ return 0;
+ }
+ }
+ }
return 0;
}