ref: 79671df4e68f1101d88ded9891e1f01be99cb189
parent: d0720d7256ca38eff6ebbd298d5f0e731d716207
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jan 4 12:13:57 EST 2019
[nm] Fix libraries dealing
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -18,7 +18,7 @@
};
extern int archive(FILE *fp);
-extern int armember(FILE *fp, char *member);
+extern long armember(FILE *fp, char *member);
extern int artraverse(FILE *fp,
int (*fn)(FILE *, char *, void *),
--- a/src/libmach/armember.c
+++ b/src/libmach/armember.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <scc/ar.h>
@@ -21,20 +22,19 @@
return dst;
}
-int
+long
armember(FILE *fp, char *member)
{
- struct ar_hdr hdr;
- long siz;
+ struct ar_hdr hdr;
+ long siz;
- if (fread(&hdr, sizeof(hdr), 1, fp) != 1)
+ if (fread(&hdr, sizeof(hdr), 1, fp) != 1)
return (feof(fp)) ? 0 : -1;
if (strncmp(hdr.ar_fmag, ARFMAG, sizeof(hdr.ar_fmag)))
return -1;
- siz = 0;
- sscanf(hdr.ar_size, "%10ld", &siz);
+ siz = strtol(hdr.ar_size, NULL, 0);
if (siz & 1)
siz++;
if (siz == 0)
@@ -42,5 +42,5 @@
getfname(&hdr, member);
- return 0;
+ return sizeof(hdr) + siz;
}
--- a/src/libmach/artraverse.c
+++ b/src/libmach/artraverse.c
@@ -14,16 +14,13 @@
for (;;) {
fgetpos(fp, &pos);
- if ((off = armember(fp, name)) < 0)
- return -1;
- r = !(*fn)(fp, name, data);
+ if ((off = armember(fp, name)) <= 0)
+ return off;
+ r = (*fn)(fp, name, data);
if (!r)
return r;
fsetpos(fp, &pos);
- fseek(fp, off, SEEK_SET);
-
- if (off == 0)
- return 0;
+ fseek(fp, off, SEEK_CUR);
}
}
--- a/src/nm/nm.c
+++ b/src/nm/nm.c
@@ -159,7 +159,7 @@
if ((t = objtest(fp, NULL)) != -1)
newobject(fp, t);
- return 0;
+ return 1;
}
static void