From 021362fb757aa84d0d409bf9bdd4323f7b6e6682 Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Thu, 2 Jul 2020 22:41:38 +0200 Subject: [PATCH] cl65: Remove temporary .o files --- src/cl65/main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cl65/main.c b/src/cl65/main.c index 9d536db82..c07e93e81 100644 --- a/src/cl65/main.c +++ b/src/cl65/main.c @@ -112,6 +112,9 @@ static CmdDesc CO65 = { 0, 0, 0, 0, 0, 0, 0 }; static CmdDesc LD65 = { 0, 0, 0, 0, 0, 0, 0 }; static CmdDesc GRC = { 0, 0, 0, 0, 0, 0, 0 }; +/* Pseudo-command to track files we want to delete */ +static CmdDesc RM = { 0, 0, 0, 0, 0, 0, 0 }; + /* Variables controlling the steps we're doing */ static int DoLink = 1; static int DoAssemble = 1; @@ -456,6 +459,19 @@ static void ExecProgram (CmdDesc* Cmd) +static void RemoveTempFiles (void) +{ + unsigned I; + for (I = 0; I < RM.FileCount; ++I) { + if (remove (RM.Files[I]) < 0) { + Warning ("Cannot remove temporary file '%s': %s", + RM.Files[I], strerror (errno)); + } + } +} + + + static void Link (void) /* Link the resulting executable */ { @@ -534,6 +550,8 @@ static void AssembleFile (const char* File, unsigned ArgCount) */ char* ObjName = MakeFilename (File, ".o"); CmdAddFile (&LD65, ObjName); + /* This is just a temporary file, schedule it for removal */ + CmdAddFile (&RM, ObjName); xfree (ObjName); } else { /* This is the final step. If an output name is given, set it */ @@ -1641,6 +1659,8 @@ int main (int argc, char* argv []) Link (); } + RemoveTempFiles (); + /* Return an apropriate exit code */ return EXIT_SUCCESS; }