ref: f252835dfc4dcd929a86547da426b5c5ab4df65b
parent: 458a063eb092b36470332d6418a3dde377e8e2be
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Feb 13 09:46:02 EST 2018
[ar] Simplify copy()
--- a/ar/main.c
+++ b/ar/main.c
@@ -139,30 +139,24 @@
}
static void
-copy(char *fname, struct ar_hdr *hdr, FILE *dst, FILE *src)
+copy(struct arop *op)
{
int c;
long siz, n;
+ struct ar_hdr *hdr = &op->hdr;
if (vflag)
- printf("a - %s\n", fname);
- fwrite(&hdr, sizeof(hdr), 1, dst);
- siz = atol(hdr->ar_size);
- if (siz < 0) {
- fprintf(stderr, "ar:corrupted member header '%s'\n", fname);
- exit(1);
- }
+ printf("a - %s\n", op->fname);
+
+ fwrite(&hdr, sizeof(hdr), 1, op->dst);
+ siz = op->size;
if ((siz & 1) == 1)
siz++;
while (siz--) {
- if ((c = getc(src)) == EOF)
+ if ((c = getc(op->src)) == EOF)
break;
- fputc(c, dst);
+ fputc(c, op->dst);
}
- if (ferror(src)) {
- perror("ar:writing temporary");
- exit(1);
- }
}
static void
@@ -292,7 +286,7 @@
{
if (inlist(op->fname, files))
return;
- copy(op->fname, &op->hdr, op->dst, op->src);
+ copy(op);
}
static char *
@@ -346,7 +340,7 @@
FILE *fp;
if (fflush(tmp) == EOF) {
- perror("ar:writing members");
+ perror("ar:writing temporary");
exit(1);
}
if (tmpafile) {