xref: /titanic_52/usr/src/cmd/sgs/include/alist.h (revision e1c679fa4b0ab8c4bcaa6263974ca0c46e5b027f)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Define an Alist, a list maintained as a reallocable array, and a for() loop
27  * macro to generalize its traversal.  Note that the array can be reallocated
28  * as it is being traversed, thus the offset of each element is recomputed from
29  * the start of the structure.
30  */
31 
32 #ifndef	_ALIST_H
33 #define	_ALIST_H
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <sys/types.h>
42 #include <sys/machelf.h>
43 
44 #define	ALO_DATA	(sizeof (Alist) - sizeof (void *))
45 
46 #define	ALIST_TRAVERSE(LIST, OFF, DATA) \
47 	(((LIST) != 0) && ((OFF) = ALO_DATA) && \
48 	(((DATA) = (void *)((char *)(LIST) + (OFF))))); \
49 	(((LIST) != 0) && ((OFF) < (LIST)->al_next)); \
50 	(((OFF) += ((LIST)->al_size)), \
51 	((DATA) = (void *)((char *)(LIST) + (OFF))))
52 
53 typedef	Word	Aliste;
54 
55 typedef struct {
56 	Aliste 		al_end;		/* offset after last al_data[] */
57 	Aliste 		al_next;	/* offset of next available al_data[] */
58 	Aliste		al_size;	/* size of each al_data[] item */
59 	void *		al_data[1];	/* data (can grow) */
60 } Alist;
61 
62 
63 /*
64  * Define alist descriptor addition return values.
65  */
66 #define	ALE_EXISTS	1		/* alist entry already exists */
67 #define	ALE_CREATE	2		/* alist entry created */
68 
69 
70 extern void	*alist_append(Alist **, const void *, size_t, int);
71 extern int	alist_delete(Alist *, const void *, Aliste *);
72 extern void	*alist_insert(Alist **, const void *, size_t, int, Aliste);
73 extern int	alist_test(Alist **, void *, size_t, int);
74 
75 #ifdef	__cplusplus
76 }
77 #endif
78 
79 #endif /* _ALIST_H */
80