From 44541066424e2ff1490f25a2b512a1a609506243 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 21 Nov 2025 05:20:35 -0500 Subject: Complain if extracted file size doesn't match orig size in ALF header. --- src/extract.c | 6 +++++- src/io.c | 5 +++++ src/unalf.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/extract.c b/src/extract.c index aa7f75b..0fb61f4 100644 --- a/src/extract.c +++ b/src/extract.c @@ -3,6 +3,7 @@ int bad_checksum, bad_checksum_count = 0; int new_file = 0; +unsigned int bytes_written = 0; char *out_filename; void dpoke(int addr, u16 value) { @@ -153,10 +154,13 @@ void extract_alf(void) { out_filename = realname; } - bad_checksum = 0; + bad_checksum = bytes_written = 0; new_file = 1; uncrunch_file(); if(bad_checksum) bad_checksum_count++; + if(bytes_written != getquad(alf_hdr_origsize0)) + fprintf(stderr, "%s: %s should be %u bytes, but extracted to %u.\n", + self, out_filename, getquad(alf_hdr_origsize0), bytes_written); if(!opts.extract_to_stdout) fclose(out_file); out_filename = 0; diff --git a/src/io.c b/src/io.c index 9a3f97d..9b664d4 100644 --- a/src/io.c +++ b/src/io.c @@ -142,5 +142,10 @@ void writeblock(void) { // fprintf(stderr, "writeblock, bufadr = $%04x, len = $%04x\n", bufadr, len); bytes = fwrite(buf, 1, len, out_file); + if(bytes < 0) { + perror(self); /* TODO: out_filename */ + exit(1); + } + bytes_written += bytes; dpoke(buf_len_l, bytes); } diff --git a/src/unalf.h b/src/unalf.h index 3c461ef..6096101 100644 --- a/src/unalf.h +++ b/src/unalf.h @@ -55,6 +55,7 @@ unsigned int getquad(int offs); /* extract.c */ extern int bad_checksum_count; extern int new_file; +extern unsigned int bytes_written; void extract_alf(void); void dpoke(int addr, u16 value); u16 dpeek(int addr); -- cgit v1.2.3