1: #include <a.out.h>
2: #define SPACE 100 /* number of symbols read at a time */
3:
4: nlist(name, list)
5: char *name;
6: struct nlist *list;
7: {
8: register struct nlist *p, *q;
9: int f, n, m, i;
10: long sa;
11: struct exec buf;
12: struct ovlhdr ovlbuf;
13: struct nlist space[SPACE];
14: register int nreq = 0;
15:
16: for(p = list; p->n_name[0]; p++) {
17: p->n_type = 0;
18: p->n_value = 0;
19: nreq++;
20: }
21: f = open(name, 0);
22: if(f < 0)
23: return(-1);
24: read(f, (char *)&buf, sizeof buf);
25: if(N_BADMAG(buf)){
26: close(f);
27: return(-1);
28: }
29: if (buf.a_syms == 0)
30: return(1);
31: sa = buf.a_text + (long)buf.a_data;
32: if ( buf.a_magic == A_MAGIC5 || buf.a_magic == A_MAGIC6)
33: {
34: sa += sizeof ovlbuf;
35: read(f, (char *)&ovlbuf, sizeof ovlbuf);
36: for(i=0; i<NOVL; i++)
37: sa += (long)ovlbuf.ov_siz[i];
38: }
39: if(buf.a_flag != 1) sa *= 2;
40: sa += sizeof buf;
41: lseek(f, sa, 0);
42: n = buf.a_syms;
43:
44: while(n){
45: m = sizeof space;
46: if(n < sizeof space)
47: m = n;
48: read(f, (char *)space, m);
49: n -= m;
50: for(q = space; (m -= sizeof(struct nlist)) >= 0; q++) {
51: for(p = list; p->n_name[0]; p++) {
52: for(i=0;i<8;i++)
53: if(p->n_name[i] != q->n_name[i]) goto cont;
54: p->n_value = q->n_value;
55: p->n_type = q->n_type;
56: if (--nreq == 0)
57: goto alldone;
58: break;
59: cont: ;
60: }
61: }
62: }
63: alldone:
64: close(f);
65: return(0);
66: }
Defined functions
nlist
defined in line
4; used 14 times
Defined macros
SPACE
defined in line
2; used 1 times