xref: /netbsd/usr.sbin/kvm_mkdb/nlist.c (revision 326b2259)
1*326b2259Sagc /* $NetBSD: nlist.c,v 1.19 2003/08/07 11:25:23 agc Exp $ */
2*326b2259Sagc 
3*326b2259Sagc /*-
4*326b2259Sagc  * Copyright (c) 1990, 1993
5*326b2259Sagc  *	The Regents of the University of California.  All rights reserved.
6*326b2259Sagc  *
7*326b2259Sagc  * Redistribution and use in source and binary forms, with or without
8*326b2259Sagc  * modification, are permitted provided that the following conditions
9*326b2259Sagc  * are met:
10*326b2259Sagc  * 1. Redistributions of source code must retain the above copyright
11*326b2259Sagc  *    notice, this list of conditions and the following disclaimer.
12*326b2259Sagc  * 2. Redistributions in binary form must reproduce the above copyright
13*326b2259Sagc  *    notice, this list of conditions and the following disclaimer in the
14*326b2259Sagc  *    documentation and/or other materials provided with the distribution.
15*326b2259Sagc  * 3. Neither the name of the University nor the names of its contributors
16*326b2259Sagc  *    may be used to endorse or promote products derived from this software
17*326b2259Sagc  *    without specific prior written permission.
18*326b2259Sagc  *
19*326b2259Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*326b2259Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*326b2259Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*326b2259Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*326b2259Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*326b2259Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*326b2259Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*326b2259Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*326b2259Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*326b2259Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*326b2259Sagc  * SUCH DAMAGE.
30*326b2259Sagc  */
3163488d73Sthorpej 
3261f28255Scgd /*-
33c347bc09Scgd  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
3461f28255Scgd  *
3561f28255Scgd  * Redistribution and use in source and binary forms, with or without
3661f28255Scgd  * modification, are permitted provided that the following conditions
3761f28255Scgd  * are met:
3861f28255Scgd  * 1. Redistributions of source code must retain the above copyright
3961f28255Scgd  *    notice, this list of conditions and the following disclaimer.
4061f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
4161f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
4261f28255Scgd  *    documentation and/or other materials provided with the distribution.
4361f28255Scgd  * 3. All advertising materials mentioning features or use of this software
4461f28255Scgd  *    must display the following acknowledgement:
4561f28255Scgd  *	This product includes software developed by the University of
4661f28255Scgd  *	California, Berkeley and its contributors.
4761f28255Scgd  * 4. Neither the name of the University nor the names of its contributors
4861f28255Scgd  *    may be used to endorse or promote products derived from this software
4961f28255Scgd  *    without specific prior written permission.
5061f28255Scgd  *
5161f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
5261f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5361f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5461f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5561f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5661f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5761f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5861f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5961f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
6061f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
6161f28255Scgd  * SUCH DAMAGE.
6261f28255Scgd  */
6361f28255Scgd 
64e5436d32Slukem #include <sys/cdefs.h>
6561f28255Scgd #ifndef lint
6663488d73Sthorpej #if 0
6763488d73Sthorpej static char sccsid[] = "from: @(#)nlist.c	8.1 (Berkeley) 6/6/93";
6863488d73Sthorpej #else
69*326b2259Sagc __RCSID("$NetBSD: nlist.c,v 1.19 2003/08/07 11:25:23 agc Exp $");
7063488d73Sthorpej #endif
7161f28255Scgd #endif /* not lint */
7261f28255Scgd 
7361f28255Scgd #include <sys/param.h>
74ec1b7778Spk 
7561f28255Scgd #include <a.out.h>
7661f28255Scgd #include <db.h>
77ec1b7778Spk #include <err.h>
7861f28255Scgd #include <errno.h>
79ec1b7778Spk #include <fcntl.h>
8061f28255Scgd #include <kvm.h>
81ec1b7778Spk #include <limits.h>
8261f28255Scgd #include <stdio.h>
8361f28255Scgd #include <stdlib.h>
84ec1b7778Spk #include <string.h>
85ec1b7778Spk #include <unistd.h>
86ec1b7778Spk 
87ec1b7778Spk #include "extern.h"
8861f28255Scgd 
89c347bc09Scgd static struct {
90c347bc09Scgd         int     (*knlist) __P((const char *, DB *));
91c347bc09Scgd } knlist_fmts[] = {
92c347bc09Scgd #ifdef NLIST_AOUT
93c347bc09Scgd         {       create_knlist_aout          },
94c347bc09Scgd #endif
95ec7f04c3Sitojun #ifdef NLIST_COFF
96ec7f04c3Sitojun         {       create_knlist_coff         },
97ec7f04c3Sitojun #endif
98c347bc09Scgd #ifdef NLIST_ECOFF
99c347bc09Scgd         {       create_knlist_ecoff         },
100c347bc09Scgd #endif
101c347bc09Scgd #ifdef NLIST_ELF32
102c347bc09Scgd         {       create_knlist_elf32         },
103c347bc09Scgd #endif
104c347bc09Scgd #ifdef NLIST_ELF64
105c347bc09Scgd         {       create_knlist_elf64         },
106c347bc09Scgd #endif
107c347bc09Scgd };
1086ff21e94Spk 
1096ff21e94Spk void
11061f28255Scgd create_knlist(name, db)
111c347bc09Scgd 	const char *name;
11261f28255Scgd 	DB *db;
11361f28255Scgd {
114c347bc09Scgd 	int i;
11561f28255Scgd 
116c347bc09Scgd         for (i = 0; i < sizeof(knlist_fmts) / sizeof(knlist_fmts[0]); i++)
117c347bc09Scgd                 if ((*knlist_fmts[i].knlist)(name, db) != -1)
118c347bc09Scgd                         return;
119c347bc09Scgd 	warnx("%s: file format not recognized", name);
120c347bc09Scgd 	punt();
12161f28255Scgd }
122