2 * "nlist.c", Peter Valkenburg, january 1989.
13 #define fail(fp) (fclose(fp), -1) /* ret. exp. when nlist fails */
15 _PROTOTYPE( int nlist
, (char *file
, struct nlist nl
[]));
18 * Nlist fills fields n_sclass and n_value of array nl with values found in
19 * non-stripped executable file. Entries that are not found have their
20 * n_value/n_sclass fields set to 0. Nl ends with a 0 or nul string n_name.
21 * The return value is -1 on failure, else the number of entries not found.
27 int nents
, nsrch
, nfound
, i
;
32 /* open executable with namelist */
33 if ((fp
= fopen(file
, "r")) == NULL
)
36 /* get header and seek to start of namelist */
37 if (fread((char *) &hd
, sizeof(struct exec
), 1, fp
) != 1 ||
38 BADMAG(hd
) || fseek(fp
, A_SYMPOS(hd
), SEEK_SET
) != 0)
41 /* determine number of entries searched for & reset fields */
43 while (nl
[nsrch
].n_name
!= NULL
&& *(nl
[nsrch
].n_name
) != '\0') {
44 nl
[nsrch
].n_sclass
= 0;
45 nl
[nsrch
].n_value
= 0;
46 nl
[nsrch
].n_type
= 0; /* for compatability */
50 /* loop through namelist & fill in user array */
52 for (nents
= (hd
.a_syms
& 0xFFFF) / sizeof(struct nlist
);
55 break; /* no need to look further */
56 if (fread((char *) &nlent
, sizeof(struct nlist
), 1, fp
) != 1)
58 for (i
= 0; i
< nsrch
; i
++)
59 if (nl
[i
].n_sclass
== 0 &&
60 strncmp(nl
[i
].n_name
, nlent
.n_name
,
61 sizeof(nlent
.n_name
)) == 0) {
70 return nsrch
- nfound
;