shithub: scc

Download patch

ref: d67fed0206b549caacc6c418aab0ac1a6bf6b9fc
parent: e28bdf554314b3258e03c75683529604efff2e2a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 16 03:50:46 EST 2018

[ar] Implement merge() used for -m

This function merges the content of the two temporary files used in -m.

--- a/ar/main.c
+++ b/ar/main.c
@@ -229,6 +229,21 @@
 static void
 merge(struct arop *op, char *list[])
 {
+	int c;
+
+	if (strcmp(op->fname, posname)) {
+		copy(&op->hdr, op->size, op->src, op->dst);
+		return;
+	}
+
+	if (aflag)
+		copy(&op->hdr, op->size, op->src, op->dst);
+
+	while ((c = getc(op->tmp)) != EOF)
+		putc(c, op->dst);
+
+	if (bflag || iflag)
+		copy(&op->hdr, op->size, op->src, op->dst);
 }
 
 static void
@@ -238,15 +253,15 @@
 		copy(&op->hdr, op->size, op->src, op->dst);
 		return;
 	}
-	if (bflag || iflag) {
-		for ( ; *list; ++list)
-			archive(*list, op->dst, 'a');
+
+	if (aflag)
 		copy(&op->hdr, op->size, op->src, op->dst);
-	} else {
+
+	for ( ; *list; ++list)
+		archive(*list, op->dst, 'a');
+
+	if (bflag || iflag)
 		copy(&op->hdr, op->size, op->src, op->dst);
-		for ( ; *list; ++list)
-			archive(*list, op->dst, 'a');
-	}
 }
 
 static void