commit a6e66128f2067e08214a36243d958d99562c4217
Author:     Quentin Rameau <[email protected]>
AuthorDate: Wed Jun 8 16:47:57 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Wed Jun 15 18:50:46 2016 +0200

    [driver] add cleanfiles
    
    This helps especially unify cleaning of temporary object files on
    success or failure alike.

diff --git a/driver/posix/scc.c b/driver/posix/scc.c
index 2d5ec31..c0efcf4 100644
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -51,10 +51,24 @@ static int nobjs;
 static int Eflag, Sflag, kflag;
 
 static void
+cleanfiles(int tool)
+{
+       struct tool *t = &tools[tool];
+       int i;
+
+       if (tool == LD && !kflag) {
+               for (i = 0; i < nobjs; ++i)
+                       unlink(tmpobjs[i]);
+       } else if (t->outfile) {
+               unlink(t->outfile);
+       }
+}
+
+static void
 terminate(void)
 {
        struct tool *t;
-       int tool, failed;
+       int tool, failed = 0;
 
        for (tool = 0; tool < LAST_TOOL; ++tool) {
                t = &tools[tool];
@@ -63,7 +77,7 @@ terminate(void)
                        if (t->error)
                                failed = tool;
                        if (tool >= failed && t->outfile)
-                               unlink(t->outfile);
+                               cleanfiles(tool);
                }
        }
 }
@@ -303,11 +317,8 @@ linkobjs(void)
        spawn(settool(inittool(LD), NULL, LAST_TOOL));
        validatetools();
 
-       if (kflag)
-               return;
-
-       for (i = 0; i < nobjs; ++i)
-               unlink(tmpobjs[i]);
+       if (!kflag)
+               cleanfiles(LD);
 }
 
 static void

Reply via email to