BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / gen / nlist.c
index b88d833..71581f9 100644 (file)
@@ -2,27 +2,44 @@
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1989 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)nlist.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)nlist.c    5.8 (Berkeley) 2/23/91";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #include <sys/file.h>
 #include <a.out.h>
 #include <stdio.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #include <sys/file.h>
 #include <a.out.h>
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 typedef struct nlist NLIST;
 #include <unistd.h>
 
 typedef struct nlist NLIST;
@@ -30,15 +47,16 @@ typedef struct nlist NLIST;
 #define        _name   n_un.n_name
 #define        ISVALID(p)      (p->_name && p->_name[0])
 
 #define        _name   n_un.n_name
 #define        ISVALID(p)      (p->_name && p->_name[0])
 
+int
 nlist(name, list)
 nlist(name, list)
-       char *name;
+       const char *name;
        NLIST *list;
 {
        register NLIST *p, *s;
        struct exec ebuf;
        FILE *fstr, *fsym;
        NLIST nbuf;
        NLIST *list;
 {
        register NLIST *p, *s;
        struct exec ebuf;
        FILE *fstr, *fsym;
        NLIST nbuf;
-       off_t curoff, strings_offset, symbol_offset, symbol_size, lseek();
+       off_t strings_offset, symbol_offset, symbol_size, lseek();
        int entries, len, maxlen;
        char sbuf[256];
 
        int entries, len, maxlen;
        char sbuf[256];
 
@@ -56,16 +74,8 @@ nlist(name, list)
        if (fseek(fsym, symbol_offset, SEEK_SET))
                goto done1;
 
        if (fseek(fsym, symbol_offset, SEEK_SET))
                goto done1;
 
-       /*
-        * some versions of stdio do lseek's on every fseek call relative
-        * to the beginning of the file.  For this reason, all string seeks
-        * are made relative to the beginning of the symbol table.
-        */
-       curoff = 0;
        if (!(fstr = fopen(name, "r")))
                goto done1;
        if (!(fstr = fopen(name, "r")))
                goto done1;
-       if (fseek(fstr, strings_offset, SEEK_SET))
-               goto done2;
 
        /*
         * clean out any left-over information for all valid entries.
 
        /*
         * clean out any left-over information for all valid entries.
@@ -88,15 +98,14 @@ nlist(name, list)
                goto done2;
        }
 
                goto done2;
        }
 
-       for (s = &nbuf; symbol_size--;) {
+       for (s = &nbuf; symbol_size; symbol_size -= sizeof(NLIST)) {
                if (fread((char *)s, sizeof(NLIST), 1, fsym) != 1)
                        goto done2;
                if (!s->_strx || s->n_type&N_STAB)
                        continue;
                if (fread((char *)s, sizeof(NLIST), 1, fsym) != 1)
                        goto done2;
                if (!s->_strx || s->n_type&N_STAB)
                        continue;
-               if (fseek(fstr, s->_strx - curoff, SEEK_CUR))
+               if (fseek(fstr, strings_offset + s->_strx, SEEK_SET))
                        goto done2;
                        goto done2;
-               curoff = s->_strx +
-                   fread(sbuf, sizeof(sbuf[0]), maxlen, fstr);
+               (void)fread(sbuf, sizeof(sbuf[0]), maxlen, fstr);
                for (p = list; ISVALID(p); p++)
                        if (!strcmp(p->_name, sbuf)) {
                                p->n_value = s->n_value;
                for (p = list; ISVALID(p); p++)
                        if (!strcmp(p->_name, sbuf)) {
                                p->n_value = s->n_value;