summaryrefslogtreecommitdiff
path: root/usr.bin/nm
diff options
context:
space:
mode:
authorpk <pk@NetBSD.org>1993-12-01 08:56:58 +0000
committerpk <pk@NetBSD.org>1993-12-01 08:56:58 +0000
commit1f4ccfa0cd3ddbfb0dae0fe651767f89f94ac9bd (patch)
tree44e0f34ac3da19f8d0e45f88a80ce1cefe990fe3 /usr.bin/nm
parent1b7c2b029931408d57e687c377444368b31cc70d (diff)
Recognise AR_EFMT1 format.
Diffstat (limited to 'usr.bin/nm')
-rw-r--r--usr.bin/nm/nm.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/usr.bin/nm/nm.c b/usr.bin/nm/nm.c
index 501999a7781..6776a652bf0 100644
--- a/usr.bin/nm/nm.c
+++ b/usr.bin/nm/nm.c
@@ -42,7 +42,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)nm.c 5.8 (Berkeley) 5/2/91";*/
-static char rcsid[] = "$Id: nm.c,v 1.2 1993/08/01 18:10:27 mycroft Exp $";
+static char rcsid[] = "$Id: nm.c,v 1.3 1993/12/01 08:56:58 pk Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -73,7 +73,7 @@ int (*sfunc)() = fname;
#define IS_EXTERNAL(x) ((x) & N_EXT)
#define SYMBOL_TYPE(x) ((x) & (N_TYPE | N_STAB))
-void *emalloc();
+void *emalloc(), *erealloc();
/*
* main()
@@ -196,8 +196,11 @@ show_archive(fname, fp)
int i, rval;
long last_ar_off;
char *p, *name;
+ int baselen, namelen;
- name = emalloc(sizeof(ar_head.ar_name) + strlen(fname) + 3);
+ baselen = strlen(fname) + 3;
+ namelen = sizeof(ar_head.ar_name);
+ name = emalloc(baselen + namelen);
rval = 0;
@@ -226,6 +229,31 @@ show_archive(fname, fp)
p = name;
if (print_file_each_line)
p += sprintf(p, "%s:", fname);
+#ifdef AR_EFMT1
+ /*
+ * BSD 4.4 extended AR format: #1/<namelen>, with name as the
+ * first <namelen> bytes of the file
+ */
+ if ( (ar_head.ar_name[0] == '#') &&
+ (ar_head.ar_name[1] == '1') &&
+ (ar_head.ar_name[2] == '/') &&
+ (isdigit(ar_head.ar_name[3]))) {
+
+ int len = atoi(&ar_head.ar_name[3]);
+ if (len > namelen) {
+ p -= (int)name;
+ name = (char *)erealloc(name, baselen+len);
+ namelen = len;
+ p += (int)name;
+ }
+ if (fread(p, len, 1, fp) != 1) {
+ (void)fprintf(stderr, "nm: %s: premature EOF.\n", name);
+ (void)free(name);
+ return 1;
+ }
+ p += len;
+ } else
+#endif
for (i = 0; i < sizeof(ar_head.ar_name); ++i)
if (ar_head.ar_name[i] && ar_head.ar_name[i] != ' ')
*p++ = ar_head.ar_name[i];
@@ -578,6 +606,18 @@ emalloc(size)
exit(1);
}
+void *
+erealloc(p, size)
+ void *p;
+ size_t size;
+{
+ /* NOSTRICT */
+ if (p = realloc(p, size))
+ return(p);
+ (void)fprintf(stderr, "nm: %s\n", strerror(errno));
+ exit(1);
+}
+
usage()
{
(void)fprintf(stderr, "usage: nm [-agnopruw] [file ...]\n");