xref: /illumos-gate/usr/src/cmd/sgs/gprof/common/printlist.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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  * Copyright (c) 1990-1997, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "gprof.h"
30 
31 /*
32  *	these are the lists of names:
33  *	there is the list head and then the listname
34  *	is a pointer to the list head
35  *	(for ease of passing to stringlist functions).
36  */
37 struct stringlist	fhead = { 0, 0 };
38 struct stringlist	*flist = &fhead;
39 struct stringlist	Fhead = { 0, 0 };
40 struct stringlist	*Flist = &Fhead;
41 struct stringlist	ehead = { 0, 0 };
42 struct stringlist	*elist = &ehead;
43 struct stringlist	Ehead = { 0, 0 };
44 struct stringlist	*Elist = &Ehead;
45 
46 void
47 addlist(struct stringlist *listp, char *funcname)
48 {
49 	struct stringlist	*slp;
50 
51 	slp = (struct stringlist *)malloc(sizeof (struct stringlist));
52 
53 	if (slp == NULL) {
54 		fprintf(stderr, "gprof: ran out room for printlist\n");
55 		exit(1);
56 	}
57 
58 	slp->next = listp->next;
59 	slp->string = funcname;
60 	listp->next = slp;
61 }
62 
63 bool
64 onlist(struct stringlist *listp, char *funcname)
65 {
66 	struct stringlist	*slp;
67 
68 	for (slp = listp->next; slp; slp = slp->next) {
69 		if (strcmp(slp->string, funcname) == 0)
70 			return (TRUE);
71 
72 		if (funcname[0] == '_' &&
73 		    strcmp(slp->string, &funcname[1]) == 0)
74 			return (TRUE);
75 	}
76 	return (FALSE);
77 }
78