diff options
Diffstat (limited to 'src/io.c')
| -rw-r--r-- | src/io.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -14,8 +14,16 @@ static void die_not_alf(void) { exit(1); } -static void eof_junk(void) { - fprintf(stderr, "%s: junk at EOF (ignoring)\n", self); +/* truncating the file by name could be a race condition, but I don't + think it's going to be a real-world problem for anyone. */ +static void eof_junk(long pos) { + fprintf(stderr, "%s: junk at EOF (%s)\n", self, opts.fixjunk ? "removing" : "ignoring"); + if(opts.fixjunk) { + if(truncate(in_filename, pos) < 0) { + fprintf(stderr, "%s: could not remove junk: ", self); + perror(in_filename); + } + } } static void check_hdr_size(const char *name, unsigned long size) { @@ -49,6 +57,9 @@ static void sanity_check_header(void) { int read_alf_header(void) { u8 h1, h2; int bytes; + long read_pos; + + read_pos = ftell(in_file); bytes = fread(mem + alf_header, 1, 29, in_file); @@ -59,7 +70,7 @@ int read_alf_header(void) { die_not_alf(); } else if(bytes < 29) { if(headers_read) { - eof_junk(); + eof_junk(read_pos); return 0; } else { die_not_alf(); @@ -79,7 +90,7 @@ int read_alf_header(void) { } if(headers_read) - eof_junk(); + eof_junk(read_pos); else die_not_alf(); |
