scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 2774ca03b4d427b15db6543e63f91886253df626
parent 8f98c55af9048f83db4d2ea523078639732617c3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 23 Feb 2018 09:47:04 +0000

[ar] Create temporary files only when it is needed

Diffstat:
Mar/main.c | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ar/main.c b/ar/main.c @@ -429,9 +429,6 @@ merge(void) FILE *fp, *fi; int c, i; - fseek(tmps[0].fp, 0, SEEK_SET); - fseek(tmps[1].fp, 0, SEEK_SET); - fseek(tmps[2].fp, 0, SEEK_SET); if ((fp = fopen(arfile, "wb")) == NULL) { perror("ar:reopening archive"); @@ -441,7 +438,9 @@ merge(void) fputs(ARMAG, fp); for (i = 0; i < 3; i++) { - fi = tmps[i].fp; + if ((fi = tmps[i].fp) == NULL) + continue; + fseek(fi , 0, SEEK_SET); while ((c = getc(fi)) != EOF) putc(c, fp); if (ferror(fi)) { @@ -461,6 +460,8 @@ closetmp(int which) { struct tmp *tmp = &tmps[which]; + if (!tmp->fp) + return; if (fclose(tmp->fp) == EOF) { perror("ar:closing temporaries"); exit(1); @@ -500,9 +501,12 @@ doit(int key, char *argv[], int argc) return; } - opentmp("ar.tmp1", BEFORE); - opentmp("ar.tmp2", INDOT); - opentmp("ar.tmp3", AFTER); + if (key == 'r' || key == 'm' || key == 'd') + opentmp("ar.tmp1", BEFORE); + if (key == 'r' || key == 'm') { + opentmp("ar.tmp2", INDOT); + opentmp("ar.tmp3", AFTER); + } switch (key) { case 'r':