shithub: scc

Download patch

ref: f482bbbc27c14ba303837d0480f0678c8f9f4a9d
parent: 07b6c8994b89abfa423d139d2d3d353a47db88c1
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 14 17:07:59 EST 2018

[ar] Avoid 2nd loop in -r

If all the files were updated in the first iteration
don't go to the second iteration where we will do
nothing.

--- a/ar/main.c
+++ b/ar/main.c
@@ -476,6 +476,7 @@
 		key = 'd';
 		break;
 	case 'r':
+		nkey++;
 		key = 'r';
 		break;
 	case 'q':
@@ -543,13 +544,19 @@
 	case 'r':
 		if (*argv == NULL)
 			return 0;
+
 		tmp1 = opentmp("ar.tmp1", &tmpafile1);
-		tmp2 = opentmp("ar.tmp2", &tmpafile2);
 		run(fp, tmp1, argv, update);
-		rewind(tmp1);
-		run(tmp1, tmp2, argv, insert);
-		closetmp(tmp1, &tmpafile1, NULL);
-		closetmp(tmp2, &tmpafile2, afile);
+
+		if (*argv == NULL) {
+			closetmp(tmp1, &tmpafile1, afile);
+		} else {
+			fseek(tmp1, SARMAG, SEEK_SET);
+			tmp2 = opentmp("ar.tmp2", &tmpafile2);
+			run(tmp1, tmp2, argv, insert);
+			closetmp(tmp1, &tmpafile1, NULL);
+			closetmp(tmp2, &tmpafile2, afile);
+		}
 		break;
 	case 'q':
 		append(fp, argv);