ref: 7046b7e3901844cf0f94f31b6b3d2415c783eea3
parent: 9b62b35493ec9d39704ca6c9a9e133a2f8e980fc
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Nov 25 04:48:57 EST 2017
[nm] Add correct output in member of archives
--- a/nm/main.c
+++ b/nm/main.c
@@ -14,12 +14,13 @@
char *argv0;
char *strings;
-int radix = 16;
-int Pflag;
-int Aflag;
-int vflag;
-int gflag;
-int uflag;
+static int radix = 16;
+static int Pflag;
+static int Aflag;
+static int vflag;
+static int gflag;
+static int uflag;
+static int archflag;
static int
object(char *fname, FILE *fp)
@@ -74,7 +75,7 @@
}
static void
-print(char *member, struct myrosym *sym, FILE *fp)
+print(char *file, char *member, struct myrosym *sym, FILE *fp)
{
char *fmt, *name = strings + sym->name;
int type = typeof(sym);
@@ -85,7 +86,7 @@
return;
if (Aflag)
- fprintf(fp, "%s: ", member);
+ fprintf(fp, (archflag) ? "%s[%s]: " : "%s: ", file, member);
if (Pflag) {
fprintf(fp, "%s %c", name, type);
if (type != 'U') {
@@ -159,7 +160,7 @@
}
qsort(syms, n, sizeof(*syms), cmp);
for (i = 0; i < n; ++i)
- print(member, &syms[i], fp);
+ print(fname, member, &syms[i], fp);
free_arrays:
@@ -179,6 +180,7 @@
struct arhdr hdr;
long pos;
+ archflag = 1;
while (rdarhdr(fp, &hdr) != EOF) {
pos = ftell(fp);
if (pos == -1 || pos > LONG_MAX - hdr.size) {
@@ -207,6 +209,7 @@
{
FILE *fp;
+ archflag = 0;
if ((fp = fopen(fname, "rb")) == NULL)
goto file_error;