|
|
1.1 ! root 1: #include <sys/types.h> ! 2: #include <a.out.h> ! 3: #include <stdio.h> ! 4: ! 5: /* ! 6: * nlist - retrieve attributes from name list (string table version) ! 7: * tangled in search of speed and buffering ! 8: */ ! 9: ! 10: #define NBSIZE 32768 ! 11: ! 12: nlist(name, list) ! 13: char *name; ! 14: struct nlist *list; ! 15: { ! 16: register struct nlist *p, *q; ! 17: register n, m; ! 18: int max, nreq; ! 19: int f, g; ! 20: off_t ss; /* start of strings */ ! 21: off_t sc; /* current string offset */ ! 22: register int soff; /* current place in strings buffer */ ! 23: int smax; /* number of bytes in strungs buffer */ ! 24: struct exec buf; ! 25: struct nlist space[BUFSIZ/sizeof(struct nlist)]; ! 26: char names[NBSIZE+2]; ! 27: ! 28: names[NBSIZE] = 'X'; /* border protection */ ! 29: names[NBSIZE+1] = 0; ! 30: max = 0; ! 31: for (q = list, nreq = 0; q->n_un.n_name && q->n_un.n_name[0]; q++, nreq++) { ! 32: q->n_type = 0; ! 33: q->n_value = 0; ! 34: q->n_desc = 0; ! 35: q->n_other = 0; ! 36: if ((n = strlen(q->n_un.n_name)) > max) ! 37: max = n; ! 38: } ! 39: if ((f = open(name, 0)) < 0) ! 40: return (-1); ! 41: if (read(f, (char *)&buf, sizeof(buf)) != sizeof(buf) ! 42: || N_BADMAG(buf)) { ! 43: close(f); ! 44: return (-1); ! 45: } ! 46: if ((g = open(name, 0)) < 0) { ! 47: close(f); ! 48: return (-1); ! 49: } ! 50: lseek(f, (off_t)N_SYMOFF(buf), 0); ! 51: ss = N_SYMOFF(buf) + buf.a_syms; ! 52: sc = 0; ! 53: smax = 0; ! 54: for (n = buf.a_syms; n > 0 && nreq > 0;) { ! 55: m = read(f, (char *)space, sizeof(space)); ! 56: if (m <= 0) ! 57: goto out; ! 58: n -= m / sizeof(struct nlist); ! 59: for (q = space; nreq > 0 && m > 0; q++, m-= sizeof(space[0])) { ! 60: if (q->n_un.n_strx == 0 || q->n_type & N_STAB) ! 61: continue; ! 62: if (sc <= q->n_un.n_strx ! 63: && q->n_un.n_strx + max <= sc + smax) ! 64: soff = q->n_un.n_strx - sc; ! 65: else { ! 66: lseek(g, ss+q->n_un.n_strx, 0); ! 67: smax = read(g, names, NBSIZE); ! 68: if (smax <= 0) ! 69: goto out; ! 70: sc = q->n_un.n_strx; ! 71: soff = 0; ! 72: } ! 73: for (p = list; p->n_un.n_name && p->n_un.n_name[0]; p++) { ! 74: if (strcmp(p->n_un.n_name, &names[soff]) == 0) { ! 75: p->n_value = q->n_value; ! 76: p->n_type = q->n_type; ! 77: p->n_desc = q->n_desc; ! 78: p->n_other = q->n_other; ! 79: --nreq; ! 80: break; ! 81: } ! 82: } ! 83: } ! 84: } ! 85: out: ! 86: close(f); ! 87: close(g); ! 88: return (0); ! 89: } ! 90:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.