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 2005 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 int alist_test(Alist **, void *, size_t, int); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #endif /* _ALIST_H */ 79