scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit a6e66128f2067e08214a36243d958d99562c4217
parent 4759de47d57fcd644fef2efddfd47894e1e1f2fb
Author: Quentin Rameau <quinq@fifth.space>
Date:   Wed,  8 Jun 2016 16:47:57 +0200

[driver] add cleanfiles

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

Diffstat:
Mdriver/posix/scc.c | 25++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git 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