4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * Routines for manipulating iidesc_t structures
41 typedef struct iidesc_find
{
47 iidesc_new(char *name
)
51 ii
= xcalloc(sizeof (iidesc_t
));
53 ii
->ii_name
= xstrdup(name
);
59 iidesc_hash(int nbuckets
, void *arg
)
65 return (hash_name(nbuckets
, ii
->ii_name
));
71 iidesc_cmp(iidesc_t
*src
, iidesc_find_t
*find
)
73 iidesc_t
*tgt
= find
->iif_tgt
;
75 if (src
->ii_type
!= tgt
->ii_type
||
76 !streq(src
->ii_name
, tgt
->ii_name
))
85 iidesc_add(hash_t
*hash
, iidesc_t
*new)
92 (void) hash_match(hash
, new, (int (*)())iidesc_cmp
, &find
);
94 if (find
.iif_ret
!= NULL
) {
95 iidesc_t
*old
= find
.iif_ret
;
97 /* replacing existing one */
98 bcopy(old
, &tmp
, sizeof (tmp
));
99 bcopy(new, old
, sizeof (*old
));
100 bcopy(&tmp
, new, sizeof (*new));
102 iidesc_free(new, NULL
);
110 iter_iidescs_by_name(tdata_t
*td
, const char *name
,
111 int (*func
)(iidesc_t
*, void *), void *data
)
114 bzero(&tmpdesc
, sizeof (iidesc_t
));
115 tmpdesc
.ii_name
= (char *)name
;
116 (void) hash_match(td
->td_iihash
, &tmpdesc
, (int (*)())func
, data
);
120 iidesc_dup(iidesc_t
*src
)
124 tgt
= xmalloc(sizeof (iidesc_t
));
125 bcopy(src
, tgt
, sizeof (iidesc_t
));
127 tgt
->ii_name
= src
->ii_name
? xstrdup(src
->ii_name
) : NULL
;
128 tgt
->ii_owner
= src
->ii_owner
? xstrdup(src
->ii_owner
) : NULL
;
131 tgt
->ii_args
= xmalloc(sizeof (tdesc_t
*) * tgt
->ii_nargs
);
132 bcopy(src
->ii_args
, tgt
->ii_args
,
133 sizeof (tdesc_t
*) * tgt
->ii_nargs
);
140 iidesc_dup_rename(iidesc_t
*src
, char const *name
, char const *owner
)
142 iidesc_t
*tgt
= iidesc_dup(src
);
146 tgt
->ii_name
= name
? xstrdup(name
) : NULL
;
147 tgt
->ii_owner
= owner
? xstrdup(owner
) : NULL
;
154 iidesc_free(iidesc_t
*idp
, void *private)
166 iidesc_dump(iidesc_t
*ii
)
168 printf("type: %d name %s\n", ii
->ii_type
,
169 (ii
->ii_name
? ii
->ii_name
: "(anon)"));
175 iidesc_count_type(void *data
, void *private)
178 iitype_t match
= (iitype_t
)private;
180 return (ii
->ii_type
== match
);
184 iidesc_stats(hash_t
*ii
)
186 printf("GFun: %5d SFun: %5d GVar: %5d SVar: %5d T %5d SOU: %5d\n",
187 hash_iter(ii
, iidesc_count_type
, (void *)II_GFUN
),
188 hash_iter(ii
, iidesc_count_type
, (void *)II_SFUN
),
189 hash_iter(ii
, iidesc_count_type
, (void *)II_GVAR
),
190 hash_iter(ii
, iidesc_count_type
, (void *)II_SVAR
),
191 hash_iter(ii
, iidesc_count_type
, (void *)II_TYPE
),
192 hash_iter(ii
, iidesc_count_type
, (void *)II_SOU
));