ref: 53c4ce7baacccf3d1b616912446c4a98984516f0
parent: d724fab92904d3e8279b22f12f3c3bf633ae22ea
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 23 04:47:04 EST 2018
[ar] Create temporary files only when it is needed
--- a/ar/main.c
+++ b/ar/main.c
@@ -429,9 +429,6 @@
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 @@
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 @@
{
struct tmp *tmp = &tmps[which];
+ if (!tmp->fp)
+ return;
if (fclose(tmp->fp) == EOF) {
perror("ar:closing temporaries");
exit(1);
@@ -500,9 +501,12 @@
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':