changeset 4:e33380b5bd46

tool/archive.c: preparation for making some vars global
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 06 Jun 2015 03:14:02 +0000
parents 003df9892e57
children 5ba13fd0e737
files tool/archive.c
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/tool/archive.c	Fri Jun 05 21:19:08 2015 +0000
+++ b/tool/archive.c	Sat Jun 06 03:14:02 2015 +0000
@@ -10,14 +10,15 @@
 #include "ar.h"
 #include "globals.h"
 
+struct ar_hdr ar_hdr;
+char member_name[17];
+unsigned member_size;
+u_char *member_body;
+
 process_archive()
 {
 	FILE *inf, *outf;
-	char ar_signature_buf[SARMAG];
-	struct ar_hdr ar_hdr;
-	char member_name[17], *cp;
-	unsigned size;
-	char *buf;
+	char ar_signature_buf[SARMAG], *cp;
 
 	inf = fopen(lib_in_filename, "r");
 	if (!inf) {
@@ -52,21 +53,21 @@
 			exit(1);
 		}
 		*cp = '\0';
-		size = strtoul(ar_hdr.ar_size, 0, 10);
-		buf = malloc(size);
-		if (!buf) {
+		member_size = strtoul(ar_hdr.ar_size, 0, 10);
+		member_body = malloc(member_size);
+		if (!member_body) {
 			fprintf(stderr,
 		"error: unable to malloc buffer for archive member \"%s\"\n",
 				member_name);
 			exit(1);
 		}
-		if (fread(buf, 1, size, inf) != size) {
+		if (fread(member_body, 1, member_size, inf) != member_size) {
 			fprintf(stderr,
 			"error reading the body of member \"%s\" from %s\n",
 				member_name, lib_in_filename);
 			exit(1);
 		}
-		if (size & 1 && getc(inf) != '\n') {
+		if (member_size & 1 && getc(inf) != '\n') {
 			fprintf(stderr,
 		"error parsing %s: no \\n after odd-sized member \"%s\"\n",
 				lib_in_filename, member_name);
@@ -75,9 +76,9 @@
 		/* the patch hook will go here */
 		/* write it out */
 		fwrite(&ar_hdr, sizeof(struct ar_hdr), 1, outf);
-		fwrite(buf, 1, size, outf);
-		free(buf);
-		if (size & 1)
+		fwrite(member_body, 1, member_size, outf);
+		free(member_body);
+		if (member_size & 1)
 			putc('\n', outf);
 	}
 	fclose(inf);