# 2.11BSD#431 - /usr/src/lib/libc/gen/nlist.c

##### Functions

    nlist             X

##### Macros

    ISVALID           X
    _name             X
    _strx             X

##### typedef's

    NLIST             X

       1: /*
       2:  * Copyright (c) 1989 The Regents of the University of California.
       3:  * All rights reserved.
       4:  *
       5:  * Redistribution and use in source and binary forms are permitted
       6:  * provided that: (1) source distributions retain this entire copyright
       7:  * notice and comment, and (2) distributions including binaries display
       8:  * the following acknowledgement:  ``This product includes software
       9:  * developed by the University of California, Berkeley and its contributors''
      10:  * in the documentation or other materials provided with the distribution
      11:  * and in all advertising materials mentioning features or use of this
      12:  * software. Neither the name of the University nor the names of its
      13:  * contributors may be used to endorse or promote products derived
      14:  * from this software without specific prior written permission.
      15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
      16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
      17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
      18:  */
      19:
      20: #if defined(LIBC_SCCS) && !defined(lint)
      21: static char sccsid[] = "@(#)nlist.c	5.7.1 (2.11BSD GTE) 12/31/93";
      22: #endif
      23:
      24: #include <sys/types.h>
      25: #include <sys/file.h>
      26: #include <a.out.h>
      27: #include <stdio.h>
      28:
      29: typedef struct nlist NLIST;
      30: #define _strx   n_un.n_strx
      31: #define _name   n_un.n_name
      32: #define ISVALID(p)  (p->_name && p->_name[0])
      33:
      34: nlist(name, list)
      35:     char *name;
      36:     NLIST *list;
      37: {
      38:     register NLIST *p, *s;
      39:     struct xexec ebuf;
      40:     FILE *fstr, *fsym;
      41:     NLIST nbuf;
      42:     off_t strings_offset, symbol_offset, symbol_size, lseek();
      43:     int entries, len, maxlen;
      44:     char sbuf[128];
      45:
      46:     entries = -1;
      47:
      48:     if (!(fsym = fopen(name, "r")))
      49:         return(-1);
      50:     if (fread((char *)&ebuf, 1, sizeof(ebuf), fsym) < sizeof (ebuf.e) ||
      51:         N_BADMAG(ebuf.e))
      52:         goto done1;
      53:
      54:     symbol_offset = N_SYMOFF(ebuf);
      55:     symbol_size = ebuf.e.a_syms;
      56:     strings_offset = N_STROFF(ebuf);
      57:     if (fseek(fsym, symbol_offset, L_SET))
      58:         goto done1;
      59:
      60:     if (!(fstr = fopen(name, "r")))
      61:         goto done1;
      62:
      63:     /*
      64: 	 * clean out any left-over information for all valid entries.
      65: 	 * Type and value defined to be 0 if not found; historical
      66: 	 * versions cleared other and desc as well.  Also figure out
      67: 	 * the largest string length so don't read any more of the
      68: 	 * string table than we have to.
      69: 	 */
      70:     for (p = list, entries = maxlen = 0; ISVALID(p); ++p, ++entries) {
      71:         p->n_type = 0;
      72:         p->n_ovly = 0;
      73:         p->n_value = 0;
      74:         if ((len = strlen(p->_name)) > maxlen)
      75:             maxlen = len;
      76:     }
      77:     if (++maxlen > sizeof(sbuf)) {      /* for the NULL */
      78:         (void)fprintf(stderr, "nlist: sym 2 big\n");
      79:         entries = -1;
      80:         goto done2;
      81:     }
      82:
      83:     for (s = &nbuf; symbol_size; symbol_size -= sizeof(NLIST)) {
      84:         if (fread((char *)s, sizeof(NLIST), 1, fsym) != 1)
      85:             goto done2;
      86:         if (!s->_strx)
      87:             continue;
      88:         if (fseek(fstr, strings_offset + s->_strx, L_SET))
      89:             goto done2;
      90:         (void)fread(sbuf, sizeof(sbuf[0]), maxlen, fstr);
      91:         for (p = list; ISVALID(p); p++)
      92:             if (!strcmp(p->_name, sbuf)) {
      93:                 p->n_value = s->n_value;
      94:                 p->n_type = s->n_type;
      95:                 p->n_ovly = s->n_ovly;
      96:                 if (!--entries)
      97:                     goto done2;
      98:             }
      99:     }
     100: done2:  (void)fclose(fstr);
     101: done1:  (void)fclose(fsym);
     102:     return(entries);
     103: }

#### Defined functions

nlist defined in line 34; used 32 times

- in /usr/src/libexec/identd/src/kernel/2.11bsd.c line 110-113(2)
- in /usr/src/local/trace.c line 21
- in /usr/src/new/kermit5.188/ckutio.c line 4107
- in /usr/src/old/checkobj/checkobj.c line 212, 243
- in /usr/src/sbin/dmesg/dmesg.c line 62-64(2)
- in /usr/src/sbin/route/route.c line 112-119(3)
- in /usr/src/sbin/savecore/savecore.c line 123
- in /usr/src/sys/autoconfig/read_nlist.c line 90
- in /usr/src/sys/conf/checksys.c line 208
- in /usr/src/ucb/PORT/systat/disks.c line 42
- in /usr/src/ucb/PORT/systat/iostat.c line 75
- in /usr/src/ucb/PORT/systat/main.c line 70
- in /usr/src/ucb/PORT/systat/mbufs.c line 107
- in /usr/src/ucb/PORT/systat/netstat.c line 109
- in /usr/src/ucb/PORT/systat/pigs.c line 166
- in /usr/src/ucb/PORT/systat/swap.c line 201
- in /usr/src/ucb/PORT/systat/vmstat.c line 163
- in /usr/src/ucb/gcore.c line 172
- in /usr/src/ucb/vmstat.c line 162
- in /usr/src/usr.bin/fstat/fstat.c line 176
- in /usr/src/usr.bin/iostat.c line 85
- in /usr/src/usr.bin/uucp/acucntrl.c line 180
- in /usr/src/usr.sbin/arp/arp.c line 279-281(2)
- in /usr/src/usr.sbin/pstat/pstat.c line 178
- in /usr/src/usr.sbin/trpt/trpt.c line 119
- in /usr/src/usr.sbin/trsp/trsp.c line 115

#### Defined variables

sccsid defined in line 21; never used

#### Defined typedef's

NLIST defined in line 29; used 5 times

- in line 36-41(3), 83-84(2)

#### Defined macros

ISVALID defined in line 32; used 2 times

- in line 70, 91

_name defined in line 31; used 4 times

- in line 32(2), 74, 92

_strx defined in line 30; used 2 times

- in line 86-88(2)

Last modified: 1994-01-09 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 616 |