[BACK]Return to nlist.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Annotation of src/lib/libc/gen/nlist.c, Revision 1.22

1.22    ! he          1: /* $NetBSD: nlist.c,v 1.21 2003/08/07 16:42:54 agc Exp $ */
1.5       cgd         2:
1.1       cgd         3: /*
1.4       cgd         4:  * Copyright (c) 1989, 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
1.21      agc        15:  * 3. Neither the name of the University nor the names of its contributors
                     16:  *    may be used to endorse or promote products derived from this software
                     17:  *    without specific prior written permission.
                     18:  *
                     19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     29:  * SUCH DAMAGE.
                     30:  */
                     31:
                     32: /*
                     33:  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
                     34:  *
                     35:  * Redistribution and use in source and binary forms, with or without
                     36:  * modification, are permitted provided that the following conditions
                     37:  * are met:
                     38:  * 1. Redistributions of source code must retain the above copyright
                     39:  *    notice, this list of conditions and the following disclaimer.
                     40:  * 2. Redistributions in binary form must reproduce the above copyright
                     41:  *    notice, this list of conditions and the following disclaimer in the
                     42:  *    documentation and/or other materials provided with the distribution.
1.1       cgd        43:  * 3. All advertising materials mentioning features or use of this software
                     44:  *    must display the following acknowledgement:
                     45:  *     This product includes software developed by the University of
                     46:  *     California, Berkeley and its contributors.
                     47:  * 4. Neither the name of the University nor the names of its contributors
                     48:  *    may be used to endorse or promote products derived from this software
                     49:  *    without specific prior written permission.
                     50:  *
                     51:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     52:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     53:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     54:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     55:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     56:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     57:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     58:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     59:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     60:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     61:  * SUCH DAMAGE.
                     62:  */
                     63:
1.11      christos   64: #include <sys/cdefs.h>
1.1       cgd        65: #if defined(LIBC_SCCS) && !defined(lint)
1.5       cgd        66: #if 0
1.4       cgd        67: static char sccsid[] = "@(#)nlist.c    8.1 (Berkeley) 6/4/93";
1.5       cgd        68: #else
1.22    ! he         69: __RCSID("$NetBSD: nlist.c,v 1.21 2003/08/07 16:42:54 agc Exp $");
1.5       cgd        70: #endif
1.1       cgd        71: #endif /* LIBC_SCCS and not lint */
                     72:
1.12      jtc        73: #include "namespace.h"
1.4       cgd        74: #include <sys/param.h>
                     75: #include <sys/mman.h>
                     76: #include <sys/stat.h>
1.1       cgd        77: #include <sys/file.h>
1.4       cgd        78:
1.14      lukem      79: #include <assert.h>
1.4       cgd        80: #include <errno.h>
1.1       cgd        81: #include <stdio.h>
                     82: #include <string.h>
                     83: #include <unistd.h>
1.22    ! he         84: #include <nlist.h>
1.12      jtc        85:
1.18      mycroft    86: #if 0
1.12      jtc        87: #ifdef __weak_alias
1.17      mycroft    88: __weak_alias(nlist,_nlist)
1.18      mycroft    89: #endif
1.12      jtc        90: #endif
1.8       cgd        91:
                     92: #include "nlist_private.h"
1.1       cgd        93:
1.13      mycroft    94: static const struct {
1.8       cgd        95:        int     (*fdnlist) __P((int, struct nlist *));
                     96: } fdnlist_fmts[] = {
                     97: #ifdef NLIST_AOUT
1.9       cgd        98:        {       __fdnlist_aout          },
1.16      msaitoh    99: #endif
                    100: #ifdef NLIST_COFF
                    101:        {       __fdnlist_coff          },
1.8       cgd       102: #endif
                    103: #ifdef NLIST_ECOFF
1.9       cgd       104:        {       __fdnlist_ecoff         },
1.8       cgd       105: #endif
                    106: #ifdef NLIST_ELF32
1.9       cgd       107:        {       __fdnlist_elf32         },
1.8       cgd       108: #endif
                    109: #ifdef NLIST_ELF64
1.9       cgd       110:        {       __fdnlist_elf64         },
1.8       cgd       111: #endif
                    112: };
                    113:
1.1       cgd       114: int
                    115: nlist(name, list)
                    116:        const char *name;
1.4       cgd       117:        struct nlist *list;
1.1       cgd       118: {
1.4       cgd       119:        int fd, n;
                    120:
1.14      lukem     121:        _DIAGASSERT(name != NULL);
                    122:        _DIAGASSERT(list != NULL);
                    123:
1.4       cgd       124:        fd = open(name, O_RDONLY, 0);
                    125:        if (fd < 0)
                    126:                return (-1);
                    127:        n = __fdnlist(fd, list);
                    128:        (void)close(fd);
                    129:        return (n);
                    130: }
1.1       cgd       131:
1.4       cgd       132: int
                    133: __fdnlist(fd, list)
1.8       cgd       134:        int fd;
                    135:        struct nlist *list;
1.4       cgd       136: {
1.20      thorpej   137:        size_t i;
                    138:        int rv;
1.6       cgd       139:
1.14      lukem     140:        _DIAGASSERT(fd != -1);
                    141:        _DIAGASSERT(list != NULL);
                    142:
1.8       cgd       143:        for (i = 0; i < sizeof(fdnlist_fmts) / sizeof(fdnlist_fmts[0]); i++)
1.10      cgd       144:                if ((rv = (*fdnlist_fmts[i].fdnlist)(fd, list)) != -1)
1.14      lukem     145:                        return (rv);
                    146:        return (-1);
1.6       cgd       147: }

CVSweb <webmaster@jp.NetBSD.org>