From cc29eb5803c4652b509900ae3024be660ded9285 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 29 Apr 2025 17:41:12 -0400 Subject: Set lengths before setting nextptr Signed-off-by: Ian Moffett --- omar.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'omar.c') diff --git a/omar.c b/omar.c index 3244415..39421b7 100644 --- a/omar.c +++ b/omar.c @@ -105,6 +105,10 @@ file_push(const char *pathname, const char *name) } } + /* Set the lengths */ + hdr.len = (pathname == NULL) ? 0 : sb.st_size; + hdr.namelen = strlen(name); + /* * The next pointer being 0 indicates that we * have reached the end of the archive. If we @@ -113,11 +117,10 @@ file_push(const char *pathname, const char *name) */ if (pathname != NULL) { hdr.nextptr = sizeof(hdr) + ALIGN_UP(hdr.len, BLOCK_SIZE); + printf("NEXT POINTER: %d\n", hdr.nextptr); } else { hdr.nextptr = 0; } - hdr.len = (pathname == NULL) ? 0 : sb.st_size; - hdr.namelen = strlen(name); memcpy(hdr.magic, "OMAR", sizeof(hdr.magic)); write(outfd, &hdr, sizeof(hdr)); write(outfd, name, hdr.namelen); -- cgit v1.2.3