shithub: scc

Download patch

ref: 00ae4645868a8de11dbb842a68fdafa4f0b63a7c
parent: d59f217f054e105fbc3230aabba5f4780279cff7
author: Quentin Rameau <quinq@fifth.space>
date: Wed Jun 8 12:47:57 EDT 2016

[driver] add cleanfiles

This helps especially unify cleaning of temporary object files on
success or failure alike.

--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -51,10 +51,24 @@
 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 @@
 			if (t->error)
 				failed = tool;
 			if (tool >= failed && t->outfile)
-				unlink(t->outfile);
+				cleanfiles(tool);
 		}
 	}
 }
@@ -303,11 +317,8 @@
 	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