xref: /illumos-gate/usr/src/cmd/sgs/gprof/common/printlist.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #include "gprof.h"
29 
30 /*
31  *	these are the lists of names:
32  *	there is the list head and then the listname
33  *	is a pointer to the list head
34  *	(for ease of passing to stringlist functions).
35  */
36 struct stringlist	fhead = { 0, 0 };
37 struct stringlist	*flist = &fhead;
38 struct stringlist	Fhead = { 0, 0 };
39 struct stringlist	*Flist = &Fhead;
40 struct stringlist	ehead = { 0, 0 };
41 struct stringlist	*elist = &ehead;
42 struct stringlist	Ehead = { 0, 0 };
43 struct stringlist	*Elist = &Ehead;
44 
45 void
addlist(struct stringlist * listp,char * funcname)46 addlist(struct stringlist *listp, char *funcname)
47 {
48 	struct stringlist	*slp;
49 
50 	slp = malloc(sizeof (struct stringlist));
51 
52 	if (slp == NULL) {
53 		(void) fprintf(stderr, "gprof: ran out room for printlist\n");
54 		exit(1);
55 	}
56 
57 	slp->next = listp->next;
58 	slp->string = funcname;
59 	listp->next = slp;
60 }
61 
62 bool
onlist(struct stringlist * listp,char * funcname)63 onlist(struct stringlist *listp, char *funcname)
64 {
65 	struct stringlist	*slp;
66 
67 	for (slp = listp->next; slp; slp = slp->next) {
68 		if (strcmp(slp->string, funcname) == 0)
69 			return (TRUE);
70 
71 		if (funcname[0] == '_' &&
72 		    strcmp(slp->string, &funcname[1]) == 0)
73 			return (TRUE);
74 	}
75 	return (FALSE);
76 }
77