Skip to content

Commit f70b8eb

Browse files
committed
Delete output file on failure.
1 parent e46a4cf commit f70b8eb

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

frontend_asm68k.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,26 @@ int main(int argc, char **argv)
461461

462462
free(combined_arguments);
463463

464+
if (source_file != NULL)
465+
fclose(source_file);
466+
467+
if (object_file != NULL)
468+
{
469+
fclose(object_file);
470+
471+
if (exit_code == EXIT_FAILURE)
472+
{
473+
/* Delete the output file; it will be junk anyway.
474+
Also, leaving a junk file will confuse Make, which will think that the assembler had previously succeeded. */
475+
remove(object_file_path);
476+
}
477+
}
478+
479+
if (listing_file != NULL)
480+
fclose(listing_file);
481+
482+
if (symbol_file != NULL)
483+
fclose(symbol_file);
484+
464485
return exit_code;
465486
}

frontend_custom.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int main(int argc, char **argv)
224224
{
225225
FILE *listing_file;
226226
FILE *symbol_file;
227+
cc_bool success;
227228

228229
if (listing_file_path == NULL)
229230
{
@@ -249,13 +250,20 @@ int main(int argc, char **argv)
249250
ERROR("Could not open symbol file.");
250251
}
251252

252-
if (!ClownAssembler_AssembleFile(input_file, output_file, stderr, listing_file, symbol_file, input_file_path != NULL ? input_file_path : "STDIN", debug, case_insensitive, equ_set_descope_local_labels, output_local_labels_to_sym_file, warnings_enabled, DefinitionCallback, NULL))
253-
ERROR("Could not assemble.");
253+
success = ClownAssembler_AssembleFile(input_file, output_file, stderr, listing_file, symbol_file, input_file_path != NULL ? input_file_path : "STDIN", debug, case_insensitive, equ_set_descope_local_labels, output_local_labels_to_sym_file, warnings_enabled, DefinitionCallback, NULL);
254254

255255
if (listing_file != NULL)
256256
fclose(listing_file);
257257

258258
fclose(output_file);
259+
260+
if (!success)
261+
{
262+
ERROR("Could not assemble.");
263+
/* Delete the output file; it will be junk anyway.
264+
Also, leaving a junk file will confuse Make, which will think that the assembler had previously succeeded. */
265+
remove(output_file_path);
266+
}
259267
}
260268

261269
fclose(input_file);

0 commit comments

Comments
 (0)